v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
dependent-code.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_DEPENDENT_CODE_H_
6#define V8_OBJECTS_DEPENDENT_CODE_H_
7
9
10// Has to be the last include (doesn't have include guards):
12#include "src/roots/roots.h"
13
14namespace v8 {
15namespace internal {
16
17enum class LazyDeoptimizeReason : uint8_t;
18
19// Dependent code is conceptually the list of {Code, DependencyGroup} tuples
20// associated with an object, where the dependency group is a reason that could
21// lead to a deopt of the corresponding code.
22//
23// Implementation details: DependentCode is a weak array list containing
24// entries, where each entry consists of a (weak) Code object and the
25// DependencyGroups bitset as a Smi.
26//
27// Note the underlying weak array list currently never shrinks physically (the
28// contents may shrink).
29// TODO(jgruber): Consider adding physical shrinking.
31 public:
33 // Group of code objects that embed a transition to this map, and depend on
34 // being deoptimized when the transition is replaced by a new version.
36 // Group of code objects that omit run-time prototype checks for prototypes
37 // described by this map. The group is deoptimized whenever the following
38 // conditions hold, possibly invalidating the assumptions embedded in the
39 // code:
40 // a) A fast-mode object described by this map changes shape (and
41 // transitions to a new map), or
42 // b) A dictionary-mode prototype described by this map changes shape, the
43 // const-ness of one of its properties changes, or its [[Prototype]]
44 // changes (only the latter causes a transition).
46 // Group of code objects that depends on global property values in property
47 // cells not being changed.
49 // Group of code objects that omit run-time checks for field(s) introduced
50 // by this map, i.e. for the field type.
54 // Group of code objects that omit run-time type checks for initial maps of
55 // constructors.
57 // Group of code objects that depend on tenuring information in
58 // AllocationSites not being changed.
60 // Group of code objects that depend on element transition information in
61 // AllocationSites not being changed.
63 // Group of code objects that depend on a slot side table property of
64 // a ScriptContext not being changed.
66 // Group of code objects that depend on particular context's extension
67 // slot to be empty.
69 // IMPORTANT: The last bit must fit into a Smi, i.e. into 31 bits.
70 };
72
73 static const char* DependencyGroupName(DependencyGroup group);
75 DependencyGroup group);
76
77 // Register a dependency of {code} on {object}, of the kinds given by
78 // {groups}.
79 V8_EXPORT_PRIVATE static void InstallDependency(Isolate* isolate,
80 Handle<Code> code,
81 Handle<HeapObject> object,
82 DependencyGroups groups);
83
84 template <typename ObjectT>
85 static void DeoptimizeDependencyGroups(Isolate* isolate, ObjectT object,
86 DependencyGroups groups);
87
88 template <typename ObjectT>
89 static void DeoptimizeDependencyGroups(Isolate* isolate,
90 Tagged<ObjectT> object,
91 DependencyGroups groups);
92
93 template <typename ObjectT>
94 static bool MarkCodeForDeoptimization(Isolate* isolate,
95 Tagged<ObjectT> object,
96 DependencyGroups groups);
97
99 const ReadOnlyRoots& roots);
101 RootIndex::kEmptyWeakArrayList;
102
103 // Constants exposed for tests.
104 static constexpr int kSlotsPerEntry =
105 2; // {code: weak InstructionStream, groups: Smi}.
106 static constexpr int kCodeSlotOffset = 0;
107 static constexpr int kGroupsSlotOffset = 1;
108
109 private:
110 // Get/Set {object}'s {DependentCode}.
114
117 DirectHandle<Code> code);
118
120 DependencyGroups deopt_groups);
121
123
124 // The callback is called for all non-cleared entries, and should return true
125 // iff the current entry should be cleared. The Function template argument
126 // must be of type: bool (Tagged<Code>, DependencyGroups).
127 template <typename Function>
128 void IterateAndCompact(IsolateForSandbox isolate, const Function& fn);
129
130 // Fills the given entry with the last non-cleared entry in this list, and
131 // returns the new length after the last non-cleared entry has been moved.
132 int FillEntryFromBack(int index, int length);
133
134 static constexpr int LengthFor(int number_of_entries) {
135 return number_of_entries * kSlotsPerEntry;
136 }
137
139};
140
142
143} // namespace internal
144} // namespace v8
145
147
148#endif // V8_OBJECTS_DEPENDENT_CODE_H_
#define DEFINE_OPERATORS_FOR_FLAGS(Type)
Definition flags.h:100
static LazyDeoptimizeReason DependencyGroupToLazyDeoptReason(DependencyGroup group)
static constexpr int kCodeSlotOffset
static void SetDependentCode(DirectHandle< HeapObject > object, DirectHandle< DependentCode > dep)
static constexpr int LengthFor(int number_of_entries)
int FillEntryFromBack(int index, int length)
static V8_EXPORT_PRIVATE Tagged< DependentCode > empty_dependent_code(const ReadOnlyRoots &roots)
OBJECT_CONSTRUCTORS(DependentCode, WeakArrayList)
static DirectHandle< DependentCode > InsertWeakCode(Isolate *isolate, Handle< DependentCode > entries, DependencyGroups groups, DirectHandle< Code > code)
static constexpr RootIndex kEmptyDependentCode
static constexpr int kSlotsPerEntry
static const char * DependencyGroupName(DependencyGroup group)
static V8_EXPORT_PRIVATE void InstallDependency(Isolate *isolate, Handle< Code > code, Handle< HeapObject > object, DependencyGroups groups)
static constexpr int kGroupsSlotOffset
static void DeoptimizeDependencyGroups(Isolate *isolate, ObjectT object, DependencyGroups groups)
void IterateAndCompact(IsolateForSandbox isolate, const Function &fn)
static bool MarkCodeForDeoptimization(Isolate *isolate, Tagged< ObjectT > object, DependencyGroups groups)
static Tagged< DependentCode > GetDependentCode(Tagged< HeapObject > object)
ZoneVector< Entry > entries
EmitFn fn
#define V8_EXPORT_PRIVATE
Definition macros.h:460