v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
pretenuring-handler.h
Go to the documentation of this file.
1// Copyright 2022 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_HEAP_PRETENURING_HANDLER_H_
6#define V8_HEAP_PRETENURING_HANDLER_H_
7
8#include <memory>
9
12#include "src/objects/map.h"
13
14namespace v8 {
15namespace internal {
16
17template <typename T>
19class Heap;
20
21class PretenuringHandler final {
22 public:
23 static constexpr int kInitialFeedbackCapacity = 256;
24
26 std::unordered_map<Tagged<AllocationSite>, size_t, Object::Hasher>;
28
29 explicit PretenuringHandler(Heap* heap);
31
32 void reset();
33
34 // If an object has an AllocationMemento trailing it, return it, otherwise
35 // return a null AllocationMemento.
36 template <FindMementoMode mode>
39 template <FindMementoMode mode>
41 Heap* heap, Tagged<Map> map, Tagged<HeapObject> object, int object_size);
42
43 // ===========================================================================
44 // Allocation site tracking. =================================================
45 // ===========================================================================
46
47 // Updates the AllocationSite of a given {object}. The entry (including the
48 // count) is cached on the local pretenuring feedback.
49 static inline void UpdateAllocationSite(
50 Heap* heap, Tagged<Map> map, Tagged<HeapObject> object, int object_size,
51 PretenuringFeedbackMap* pretenuring_feedback);
52
53 // Merges local pretenuring feedback into the global one. Note that this
54 // method needs to be called after evacuation, as allocation sites may be
55 // evacuated and this method resolves forward pointers accordingly.
57 const PretenuringFeedbackMap& local_pretenuring_feedback);
58
59 // Adds an allocation site to the list of sites to be pretenured during the
60 // next collection. Added allocation sites are pretenured independent of
61 // their feedback.
64
65 // ===========================================================================
66 // Pretenuring. ==============================================================
67 // ===========================================================================
68
69 // Pretenuring decisions are made based on feedback collected during new space
70 // evacuation. Note that between feedback collection and calling this method
71 // object in old space must not move.
72 void ProcessPretenuringFeedback(size_t new_space_capacity_before_gc);
73
74 // Removes an entry from the global pretenuring storage.
76
78 return !global_pretenuring_feedback_.empty();
79 }
80
82
83 private:
84 Heap* const heap_;
85
86 // The feedback storage is used to store allocation sites (keys) and how often
87 // they have been visited (values) by finding a memento behind an object. The
88 // storage is only alive temporary during a GC. The invariant is that all
89 // pointers in this map are already fixed, i.e., they do not point to
90 // forwarding pointers.
92
93 std::unique_ptr<GlobalHandleVector<AllocationSite>>
95};
96
97} // namespace internal
98} // namespace v8
99
100#endif // V8_HEAP_PRETENURING_HANDLER_H_
void ProcessPretenuringFeedback(size_t new_space_capacity_before_gc)
static constexpr int kInitialFeedbackCapacity
std::unordered_map< Tagged< AllocationSite >, size_t, Object::Hasher > PretenuringFeedbackMap
static Tagged< AllocationMemento > FindAllocationMemento(Heap *heap, Tagged< Map > map, Tagged< HeapObject > object)
std::unique_ptr< GlobalHandleVector< AllocationSite > > allocation_sites_to_pretenure_
void RemoveAllocationSitePretenuringFeedback(Tagged< AllocationSite > site)
void MergeAllocationSitePretenuringFeedback(const PretenuringFeedbackMap &local_pretenuring_feedback)
V8_EXPORT_PRIVATE void PretenureAllocationSiteOnNextCollection(Tagged< AllocationSite > site)
PretenuringFeedbackMap global_pretenuring_feedback_
static V8_EXPORT_PRIVATE int GetMinMementoCountForTesting()
static void UpdateAllocationSite(Heap *heap, Tagged< Map > map, Tagged< HeapObject > object, int object_size, PretenuringFeedbackMap *pretenuring_feedback)
#define V8_EXPORT_PRIVATE
Definition macros.h:460