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/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, bytecode_flushing_candidates, \ 61 BytecodeFlushingCandidates) \ 62 F(JSFunction, flushed_js_functions, FlushedJSFunctions) 63 64 class WeakObjects { 65 public: 66 template <typename Type> 67 using WeakObjectWorklist = Worklist<Type, 64>; 68 69 #define DECLARE_WORKLIST(Type, name, _) WeakObjectWorklist<Type> name; 70 WEAK_OBJECT_WORKLISTS(DECLARE_WORKLIST) 71 #undef DECLARE_WORKLIST 72 73 void UpdateAfterScavenge(); 74 75 private: 76 #define DECLARE_UPDATE_METHODS(Type, _, Name) \ 77 void Update##Name(WeakObjectWorklist<Type>&); 78 WEAK_OBJECT_WORKLISTS(DECLARE_UPDATE_METHODS) 79 #undef DECLARE_UPDATE_METHODS 80 81 #ifdef DEBUG 82 template <typename Type> 83 bool ContainsYoungObjects(WeakObjectWorklist<Type>& worklist); 84 #endif 85 }; 86 87 } // namespace internal 88 } // namespace v8 89 90 #endif // V8_HEAP_WEAK_OBJECT_WORKLISTS_H_ 91