v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
linear-allocation-area.h
Go to the documentation of this file.
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_HEAP_LINEAR_ALLOCATION_AREA_H_
6#define V8_HEAP_LINEAR_ALLOCATION_AREA_H_
7
8// This header file is included outside of src/heap/.
9// Avoid including src/heap/ internals.
10#include "include/v8-internal.h"
11#include "src/common/checks.h"
12
13namespace v8 {
14namespace internal {
15
16// A linear allocation area to allocate objects from.
17//
18// Invariant that must hold at all times:
19// start <= top <= limit
21 public:
24 : start_(top), top_(top), limit_(limit) {
25 Verify();
26 }
27
28 void Reset(Address top, Address limit) {
29 start_ = top;
30 top_ = top;
31 limit_ = limit;
32 Verify();
33 }
34
35 void ResetStart() { start_ = top_; }
36
37 V8_INLINE bool CanIncrementTop(size_t bytes) const {
38 Verify();
39 return (top_ + bytes) <= limit_;
40 }
41
43 Address old_top = top_;
44 top_ += bytes;
45 Verify();
46 return old_top;
47 }
48
49 V8_INLINE bool DecrementTopIfAdjacent(Address new_top, size_t bytes) {
50 Verify();
51 if ((new_top + bytes) == top_) {
52 top_ = new_top;
53 if (start_ > top_) {
54 ResetStart();
55 }
56 Verify();
57 return true;
58 }
59 return false;
60 }
61
63 Verify();
64 other.Verify();
65 if (top_ == other.limit_) {
66 top_ = other.top_;
67 start_ = other.start_;
68 other.Reset(kNullAddress, kNullAddress);
69 Verify();
70 return true;
71 }
72 return false;
73 }
74
76 limit_ = limit;
77 Verify();
78 }
79
81 Verify();
82 return start_;
83 }
85 Verify();
86 return top_;
87 }
89 Verify();
90 return limit_;
91 }
92 const Address* top_address() const { return &top_; }
93 Address* top_address() { return &top_; }
94 const Address* limit_address() const { return &limit_; }
96
97 void Verify() const {
98#ifdef DEBUG
103 } else {
105 }
106#endif // DEBUG
107 }
108
109 static constexpr int kSize = 3 * kSystemPointerSize;
110
111 private:
112 // The start of the LAB. Initially coincides with `top_`. As top is moved
113 // ahead, the area [start_, top_[ denotes a range of new objects. This range
114 // is reset with `ResetStart()`.
116 // The top of the LAB that is used for allocation.
118 // Limit of the LAB the denotes the end of the valid range for allocation.
120};
121
123 "LinearAllocationArea's size must be small because it "
124 "is included in IsolateData.");
125
126} // namespace internal
127} // namespace v8
128
129#endif // V8_HEAP_LINEAR_ALLOCATION_AREA_H_
#define SLOW_DCHECK(condition)
Definition checks.h:21
void Reset(Address top, Address limit)
V8_INLINE bool DecrementTopIfAdjacent(Address new_top, size_t bytes)
V8_INLINE bool CanIncrementTop(size_t bytes) const
V8_INLINE void SetLimit(Address limit)
V8_INLINE Address IncrementTop(size_t bytes)
V8_INLINE bool MergeIfAdjacent(LinearAllocationArea &other)
LinearAllocationArea(Address top, Address limit)
#define V8_COMPRESS_POINTERS_8GB_BOOL
Definition globals.h:608
constexpr intptr_t kObjectAlignment
Definition globals.h:930
constexpr int kSystemPointerSize
Definition globals.h:410
constexpr intptr_t kObjectAlignment8GbHeap
Definition globals.h:934
static constexpr Address kNullAddress
Definition v8-internal.h:53
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403
#define V8_INLINE
Definition v8config.h:500