v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
page-pool.h
Go to the documentation of this file.
1// Copyright 2025 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_PAGE_POOL_H_
6#define V8_HEAP_PAGE_POOL_H_
7
8#include "absl/container/flat_hash_map.h"
11
12namespace v8 {
13namespace internal {
14
15class Isolate;
16class MutablePageMetadata;
17
18// Pool keeps pages allocated and accessible until explicitly flushed.
19class PagePool {
20 public:
21 PagePool() = default;
22 ~PagePool();
23
24 PagePool(const PagePool&) = delete;
25 PagePool& operator=(const PagePool&) = delete;
26
27 // Adds page to the pool.
28 void Add(Isolate* isolate, MutablePageMetadata* chunk);
29
30 // Tries to get page from the pool. Order of priority for pools:
31 // (1) Local pool for the isolate.
32 // (2) Shared pool.
33 // (3) Steal from another isolate.
35
36 // Used to release the local page pool for this isolate on isolate teardown.
37 // If a task can be scheduled on another isolate, freeing of pooled pages will
38 // be delayed to give other isolates the chance to make use of its pooled
39 // pages. If this is not possible pages will be freed immediately.
40 void ReleaseOnTearDown(Isolate* isolate);
41
42 // Releases the pooled pages immediately.
44
45 // Tear down this page pool. Frees all pooled pages immediately.
46 void TearDown();
47
48 // Released shared pool pages at least as old as `id`. Returns the number of
49 // freed pages.
50 size_t ReleaseUpTo(size_t id);
51
52 // Returns the number of pages in the local pool for the given isolate.
53 size_t GetCount(Isolate* isolate) const;
54
55 // Returns the number of pages in the shared pool.
56 size_t GetSharedCount() const;
57
58 // Returns the number of pages cached in all local pools and the shared pool.
59 size_t GetTotalCount() const;
60
61 private:
62 absl::flat_hash_map<Isolate*, std::vector<MutablePageMetadata*>> local_pools;
63 // Shared pages are tracked with a logical time. This allows `ReleaseUpTo()`
64 // to free all those pages where enough time has passed.
65 std::vector<std::pair<std::vector<MutablePageMetadata*>, size_t>>
67 size_t next_id_ = 1;
68
70};
71
72} // namespace internal
73} // namespace v8
74
75#endif // V8_HEAP_PAGE_POOL_H_
std::vector< std::pair< std::vector< MutablePageMetadata * >, size_t > > shared_pool_
Definition page-pool.h:66
V8_EXPORT_PRIVATE void ReleaseImmediately(Isolate *isolate)
Definition page-pool.cc:80
void ReleaseOnTearDown(Isolate *isolate)
Definition page-pool.cc:43
size_t GetSharedCount() const
Definition page-pool.cc:147
size_t GetCount(Isolate *isolate) const
Definition page-pool.cc:137
MutablePageMetadata * Remove(Isolate *isolate)
Definition page-pool.cc:186
PagePool & operator=(const PagePool &)=delete
size_t GetTotalCount() const
Definition page-pool.cc:158
void Add(Isolate *isolate, MutablePageMetadata *chunk)
Definition page-pool.cc:173
absl::flat_hash_map< Isolate *, std::vector< MutablePageMetadata * > > local_pools
Definition page-pool.h:62
PagePool(const PagePool &)=delete
size_t ReleaseUpTo(size_t id)
Definition page-pool.cc:110
#define V8_EXPORT_PRIVATE
Definition macros.h:460