v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
evacuation-allocator.cc
Go to the documentation of this file.
1// Copyright 2023 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
6
8
9namespace v8 {
10namespace internal {
11
13 Heap* heap, CompactionSpaceKind compaction_space_kind)
14 : heap_(heap),
15 new_space_(heap->new_space()),
16 compaction_spaces_(heap, compaction_space_kind) {
17 if (new_space_) {
20 }
21
26 if (heap_->isolate()->has_shared_space()) {
27 shared_space_allocator_.emplace(heap, compaction_spaces_.Get(SHARED_SPACE),
28 MainAllocator::kInGC);
29 }
32}
33
35 Tagged<HeapObject> object, int object_size) {
37 object_size = ALIGN_TO_ALLOCATION_ALIGNMENT(object_size);
38 switch (space) {
39 case NEW_SPACE:
40 FreeLastInMainAllocator(new_space_allocator(), object, object_size);
41 return;
42 case OLD_SPACE:
43 FreeLastInMainAllocator(old_space_allocator(), object, object_size);
44 return;
45 case SHARED_SPACE:
46 FreeLastInMainAllocator(shared_space_allocator(), object, object_size);
47 return;
48 default:
49 // Only new and old space supported.
51 }
52}
53
55 Tagged<HeapObject> object,
56 int object_size) {
57 if (!allocator->TryFreeLast(object.address(), object_size)) {
58 // We couldn't free the last object so we have to write a proper filler.
59 heap_->CreateFillerObjectAt(object.address(), object_size);
60 }
61}
62
84
85} // namespace internal
86} // namespace v8
CompactionSpace * Get(AllocationSpace space)
std::optional< MainAllocator > trusted_space_allocator_
void FreeLastInMainAllocator(MainAllocator *allocator, Tagged< HeapObject > object, int object_size)
std::optional< MainAllocator > shared_space_allocator_
EvacuationAllocator(Heap *heap, CompactionSpaceKind compaction_space_kind)
std::optional< MainAllocator > old_space_allocator_
CompactionSpaceCollection compaction_spaces_
std::optional< MainAllocator > code_space_allocator_
void FreeLast(AllocationSpace space, Tagged< HeapObject > object, int object_size)
std::optional< MainAllocator > new_space_allocator_
MainAllocator * new_space_allocator()
V8_EXPORT_PRIVATE void CreateFillerObjectAt(Address addr, int size, ClearFreedMemoryMode clear_memory_mode=ClearFreedMemoryMode::kDontClearFreedMemory)
Definition heap.cc:3202
OldSpace * old_space() const
Definition heap.h:730
TrustedSpace * trusted_space() const
Definition heap.h:739
CodeSpace * code_space() const
Definition heap.h:732
PagedSpace * shared_allocation_space() const
Definition heap.h:750
Isolate * isolate() const
Definition heap-inl.h:61
HeapAllocator * allocator()
Definition heap.h:1640
bool has_shared_space() const
Definition isolate.h:2303
static constexpr InGCTag kInGC
V8_INLINE bool IsLabValid() const
V8_EXPORT_PRIVATE void FreeLinearAllocationArea()
void MergeCompactionSpace(CompactionSpace *other)
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
Heap * heap_