• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_WEAK_OBJECT_WORKLISTS_H_
6 #define V8_HEAP_WEAK_OBJECT_WORKLISTS_H_
7 
8 #include "src/common/globals.h"
9 #include "src/heap/base/worklist.h"
10 #include "src/objects/heap-object.h"
11 #include "src/objects/js-weak-refs.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 struct Ephemeron {
17   HeapObject key;
18   HeapObject value;
19 };
20 
21 using HeapObjectAndSlot = std::pair<HeapObject, HeapObjectSlot>;
22 using HeapObjectAndCode = std::pair<HeapObject, Code>;
23 class EphemeronHashTable;
24 class JSFunction;
25 class SharedFunctionInfo;
26 class TransitionArray;
27 
28 // Weak objects and weak references discovered during incremental/concurrent
29 // marking. They are processed in ClearNonLiveReferences after marking.
30 // Each entry in this list specifies:
31 // 1) Type of the worklist entry.
32 // 2) Lower-case name of the worklsit.
33 // 3) Capitalized name of the worklist.
34 //
35 // If you add a new entry, then you also need to implement the corresponding
36 // Update*() function in the cc file for updating pointers after Scavenge.
37 #define WEAK_OBJECT_WORKLISTS(F)                                             \
38   F(TransitionArray, transition_arrays, TransitionArrays)                    \
39   /* Keep track of all EphemeronHashTables in the heap to process            \
40      them in the atomic pause. */                                            \
41   F(EphemeronHashTable, ephemeron_hash_tables, EphemeronHashTables)          \
42   /* Keep track of all ephemerons for concurrent marking tasks. Only store   \
43      ephemerons in these worklists if both (key, value) are unreachable at   \
44      the moment.                                                             \
45      MarkCompactCollector::ProcessEphemeronsUntilFixpoint drains/fills       \
46      these worklists. current_ephemerons is used as draining worklist in     \
47      the current fixpoint iteration. */                                      \
48   F(Ephemeron, current_ephemerons, CurrentEphemerons)                        \
49   /* Stores ephemerons to visit in the next fixpoint iteration. */           \
50   F(Ephemeron, next_ephemerons, NextEphemerons)                              \
51   /* When draining the marking worklist new discovered ephemerons are pushed \
52       into this worklist. */                                                 \
53   F(Ephemeron, discovered_ephemerons, DiscoveredEphemerons)                  \
54   /* TODO(marja): For old space, we only need the slot, not the host object. \
55      Optimize this by adding a different storage for old space. */           \
56   F(HeapObjectAndSlot, weak_references, WeakReferences)                      \
57   F(HeapObjectAndCode, weak_objects_in_code, WeakObjectsInCode)              \
58   F(JSWeakRef, js_weak_refs, JSWeakRefs)                                     \
59   F(WeakCell, weak_cells, WeakCells)                                         \
60   F(SharedFunctionInfo, code_flushing_candidates, CodeFlushingCandidates)    \
61   F(JSFunction, baseline_flushing_candidates, BaselineFlushingCandidates)    \
62   F(JSFunction, flushed_js_functions, FlushedJSFunctions)
63 
64 class WeakObjects final {
65  private:
66   class UnusedBase {};  // Base class to allow using macro in initializer list.
67 
68  public:
69   template <typename Type>
70   using WeakObjectWorklist = ::heap::base::Worklist<Type, 64>;
71 
72   class Local final : public UnusedBase {
73    public:
74     explicit Local(WeakObjects* weak_objects);
75 
76     V8_EXPORT_PRIVATE void Publish();
77 
78 #define DECLARE_WORKLIST(Type, name, _) \
79   WeakObjectWorklist<Type>::Local name##_local;
80     WEAK_OBJECT_WORKLISTS(DECLARE_WORKLIST)
81 #undef DECLARE_WORKLIST
82   };
83 
84 #define DECLARE_WORKLIST(Type, name, _) WeakObjectWorklist<Type> name;
85   WEAK_OBJECT_WORKLISTS(DECLARE_WORKLIST)
86 #undef DECLARE_WORKLIST
87 
88   void UpdateAfterScavenge();
89   void Clear();
90 
91  private:
92 #define DECLARE_UPDATE_METHODS(Type, _, Name) \
93   static void Update##Name(WeakObjectWorklist<Type>&);
94   WEAK_OBJECT_WORKLISTS(DECLARE_UPDATE_METHODS)
95 #undef DECLARE_UPDATE_METHODS
96 
97 #ifdef DEBUG
98   template <typename Type>
99   static bool ContainsYoungObjects(WeakObjectWorklist<Type>& worklist);
100 #endif
101 };
102 
103 }  // namespace internal
104 }  // namespace v8
105 
106 #endif  // V8_HEAP_WEAK_OBJECT_WORKLISTS_H_
107