• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REFERENCE_SUMMARIZER_H_
6 #define V8_HEAP_REFERENCE_SUMMARIZER_H_
7 
8 #include <unordered_set>
9 
10 #include "src/objects/heap-object.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class Heap;
16 
17 class ReferenceSummary {
18  public:
19   ReferenceSummary() = default;
ReferenceSummary(ReferenceSummary && other)20   ReferenceSummary(ReferenceSummary&& other) V8_NOEXCEPT
21       : strong_references_(std::move(other.strong_references_)),
22         weak_references_(std::move(other.weak_references_)) {}
23 
24   // Produces a set of objects referred to by the object. This function uses a
25   // realistic marking visitor, so its results are likely to match real GC
26   // behavior. Intended only for verification.
27   static ReferenceSummary SummarizeReferencesFrom(Heap* heap, HeapObject obj);
28 
29   // All objects which the chosen object has strong pointers to.
strong_references()30   std::unordered_set<HeapObject, Object::Hasher>& strong_references() {
31     return strong_references_;
32   }
33 
34   // All objects which the chosen object has weak pointers to. The values in
35   // ephemeron hash tables are also included here, even though they aren't
36   // normal weak pointers.
weak_references()37   std::unordered_set<HeapObject, Object::Hasher>& weak_references() {
38     return weak_references_;
39   }
40 
Clear()41   void Clear() {
42     strong_references_.clear();
43     weak_references_.clear();
44   }
45 
46  private:
47   std::unordered_set<HeapObject, Object::Hasher> strong_references_;
48   std::unordered_set<HeapObject, Object::Hasher> weak_references_;
49   DISALLOW_GARBAGE_COLLECTION(no_gc)
50 };
51 
52 }  // namespace internal
53 }  // namespace v8
54 
55 #endif  // V8_HEAP_REFERENCE_SUMMARIZER_H_
56