• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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_BASE_ACTIVE_SYSTEM_PAGES_H_
6 #define V8_HEAP_BASE_ACTIVE_SYSTEM_PAGES_H_
7 
8 #include <bitset>
9 #include <cstdint>
10 
11 #include "src/base/macros.h"
12 
13 namespace heap {
14 namespace base {
15 
16 // Class implements a bitset of system pages on a heap page.
17 class ActiveSystemPages final {
18  public:
19   // Defines the maximum number of system pages that can be tracked in one
20   // instance.
21   static constexpr size_t kMaxPages = 64;
22 
23   // Initializes the set of active pages to the system pages for the header.
24   V8_EXPORT_PRIVATE size_t Init(size_t header_size, size_t page_size_bits,
25                                 size_t user_page_size);
26 
27   // Adds the pages for this memory range. Returns the number of freshly added
28   // pages.
29   V8_EXPORT_PRIVATE size_t Add(size_t start, size_t end, size_t page_size_bits);
30 
31   // Replaces the current bitset with the given argument. The new bitset needs
32   // to be a proper subset of the current pages, which means this operation
33   // can't add pages. Returns the number of removed pages.
34   V8_EXPORT_PRIVATE size_t Reduce(ActiveSystemPages updated_value);
35 
36   // Removes all pages. Returns the number of removed pages.
37   V8_EXPORT_PRIVATE size_t Clear();
38 
39   // Returns the memory used with the given page size.
40   V8_EXPORT_PRIVATE size_t Size(size_t page_size_bits) const;
41 
42  private:
43   using bitset_t = std::bitset<kMaxPages>;
44 
45   bitset_t value_;
46 };
47 
48 }  // namespace base
49 }  // namespace heap
50 
51 #endif  // V8_HEAP_BASE_ACTIVE_SYSTEM_PAGES_H_
52