1 // Copyright 2021 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_PROFILER_WEAK_CODE_REGISTRY_H_ 6 #define V8_PROFILER_WEAK_CODE_REGISTRY_H_ 7 8 #include <vector> 9 10 #include "src/execution/isolate.h" 11 #include "src/objects/objects.h" 12 #include "src/profiler/profile-generator.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class V8_EXPORT_PRIVATE WeakCodeRegistry { 18 public: 19 struct Listener { 20 virtual void OnHeapObjectDeletion(CodeEntry* entry) = 0; 21 }; 22 WeakCodeRegistry(Isolate * isolate)23 explicit WeakCodeRegistry(Isolate* isolate) : isolate_(isolate) {} ~WeakCodeRegistry()24 ~WeakCodeRegistry() { Clear(); } 25 26 void Track(CodeEntry* entry, Handle<AbstractCode> code); 27 28 // Removes all dead code objects from the registry, invoking the provided 29 // listener for each new CodeEntry that is no longer referenced on the heap 30 // (if set). 31 void Sweep(Listener* listener); 32 33 // Removes all heap object tracking from stored CodeEntries. 34 void Clear(); 35 36 private: 37 Isolate* const isolate_; 38 // Invariant: Entries will always be removed here before the CodeMap is 39 // destroyed. CodeEntries should not be freed while their heap objects exist. 40 std::vector<CodeEntry*> entries_; 41 }; 42 43 } // namespace internal 44 } // namespace v8 45 46 #endif // V8_PROFILER_WEAK_CODE_REGISTRY_H_ 47