v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
base-space.h
Go to the documentation of this file.
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_BASE_SPACE_H_
6#define V8_HEAP_BASE_SPACE_H_
7
8#include <atomic>
9
10#include "src/base/macros.h"
11#include "src/common/globals.h"
14
15namespace v8 {
16namespace internal {
17
18class Heap;
19
20// ----------------------------------------------------------------------------
21// BaseSpace is the abstract superclass for all allocation spaces.
23 public:
24 BaseSpace(const BaseSpace&) = delete;
25 BaseSpace& operator=(const BaseSpace&) = delete;
26
27 Heap* heap() const {
29 return heap_;
30 }
31
32 AllocationSpace identity() const { return id_; }
33
34 // Return the total amount committed memory for this space, i.e., allocatable
35 // memory and page headers.
36 virtual size_t CommittedMemory() const { return committed_; }
37
38 virtual size_t MaximumCommittedMemory() const { return max_committed_; }
39
40 // Approximate amount of physical memory committed for this space.
41 virtual size_t CommittedPhysicalMemory() const = 0;
42
43 // Returns allocated size.
44 virtual size_t Size() const = 0;
45
46#ifdef VERIFY_HEAP
47 virtual void Verify(Isolate* isolate,
48 SpaceVerificationVisitor* visitor) const = 0;
49#endif // VERIFY_HEAP
50
51 protected:
53
54 virtual ~BaseSpace() = default;
55
56 void AccountCommitted(size_t bytes) {
57 DCHECK_GE(committed_ + bytes, committed_);
58 committed_ += bytes;
59 if (committed_ > max_committed_) {
60 max_committed_ = committed_;
61 }
62 }
63
64 void AccountUncommitted(size_t bytes) {
65 DCHECK_GE(committed_, committed_ - bytes);
66 committed_ -= bytes;
67 }
68
69 protected:
72
73 // Keeps track of committed memory in a space.
74 std::atomic<size_t> committed_{0};
75 size_t max_committed_ = 0;
76};
77
78} // namespace internal
79} // namespace v8
80
81#endif // V8_HEAP_BASE_SPACE_H_
BaseSpace(Heap *heap, AllocationSpace id)
Definition base-space.h:52
Heap * heap() const
Definition base-space.h:27
void AccountCommitted(size_t bytes)
Definition base-space.h:56
void AccountUncommitted(size_t bytes)
Definition base-space.h:64
virtual size_t CommittedPhysicalMemory() const =0
AllocationSpace identity() const
Definition base-space.h:32
virtual size_t MaximumCommittedMemory() const
Definition base-space.h:38
virtual size_t CommittedMemory() const
Definition base-space.h:36
BaseSpace & operator=(const BaseSpace &)=delete
AllocationSpace id_
Definition base-space.h:71
BaseSpace(const BaseSpace &)=delete
virtual size_t Size() const =0
virtual ~BaseSpace()=default
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define V8_EXPORT_PRIVATE
Definition macros.h:460
Heap * heap_