• 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_CODE_OBJECT_REGISTRY_H_
6 #define V8_HEAP_CODE_OBJECT_REGISTRY_H_
7 
8 #include <set>
9 #include <vector>
10 
11 #include "src/base/macros.h"
12 #include "src/common/globals.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 // The CodeObjectRegistry holds all start addresses of code objects of a given
18 // MemoryChunk. Each MemoryChunk owns a separate CodeObjectRegistry. The
19 // CodeObjectRegistry allows fast lookup from an inner pointer of a code object
20 // to the actual code object.
21 class V8_EXPORT_PRIVATE CodeObjectRegistry {
22  public:
23   void RegisterNewlyAllocatedCodeObject(Address code);
24   void RegisterAlreadyExistingCodeObject(Address code);
25   void Clear();
26   void Finalize();
27   bool Contains(Address code) const;
28   Address GetCodeObjectStartFromInnerAddress(Address address) const;
29 
30  private:
31   // A vector of addresses, which may be sorted. This is set to 'mutable' so
32   // that it can be lazily sorted during GetCodeObjectStartFromInnerAddress.
33   mutable std::vector<Address> code_object_registry_;
34   mutable bool is_sorted_ = true;
35 };
36 
37 }  // namespace internal
38 }  // namespace v8
39 
40 #endif  // V8_HEAP_CODE_OBJECT_REGISTRY_H_
41