11cb0ef41Sopenharmony_ci// Copyright 2022 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_HEAP_REFERENCE_SUMMARIZER_H_
61cb0ef41Sopenharmony_ci#define V8_HEAP_REFERENCE_SUMMARIZER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <unordered_set>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/objects/heap-object.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass Heap;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciclass ReferenceSummary {
181cb0ef41Sopenharmony_ci public:
191cb0ef41Sopenharmony_ci  ReferenceSummary() = default;
201cb0ef41Sopenharmony_ci  ReferenceSummary(ReferenceSummary&& other) V8_NOEXCEPT
211cb0ef41Sopenharmony_ci      : strong_references_(std::move(other.strong_references_)),
221cb0ef41Sopenharmony_ci        weak_references_(std::move(other.weak_references_)) {}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  // Produces a set of objects referred to by the object. This function uses a
251cb0ef41Sopenharmony_ci  // realistic marking visitor, so its results are likely to match real GC
261cb0ef41Sopenharmony_ci  // behavior. Intended only for verification.
271cb0ef41Sopenharmony_ci  static ReferenceSummary SummarizeReferencesFrom(Heap* heap, HeapObject obj);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  // All objects which the chosen object has strong pointers to.
301cb0ef41Sopenharmony_ci  std::unordered_set<HeapObject, Object::Hasher>& strong_references() {
311cb0ef41Sopenharmony_ci    return strong_references_;
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  // All objects which the chosen object has weak pointers to. The values in
351cb0ef41Sopenharmony_ci  // ephemeron hash tables are also included here, even though they aren't
361cb0ef41Sopenharmony_ci  // normal weak pointers.
371cb0ef41Sopenharmony_ci  std::unordered_set<HeapObject, Object::Hasher>& weak_references() {
381cb0ef41Sopenharmony_ci    return weak_references_;
391cb0ef41Sopenharmony_ci  }
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  void Clear() {
421cb0ef41Sopenharmony_ci    strong_references_.clear();
431cb0ef41Sopenharmony_ci    weak_references_.clear();
441cb0ef41Sopenharmony_ci  }
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci private:
471cb0ef41Sopenharmony_ci  std::unordered_set<HeapObject, Object::Hasher> strong_references_;
481cb0ef41Sopenharmony_ci  std::unordered_set<HeapObject, Object::Hasher> weak_references_;
491cb0ef41Sopenharmony_ci  DISALLOW_GARBAGE_COLLECTION(no_gc)
501cb0ef41Sopenharmony_ci};
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci}  // namespace internal
531cb0ef41Sopenharmony_ci}  // namespace v8
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci#endif  // V8_HEAP_REFERENCE_SUMMARIZER_H_
56