v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
live-object-range-inl.h
Go to the documentation of this file.
1// Copyright 2024 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_LIVE_OBJECT_RANGE_INL_H_
6#define V8_HEAP_LIVE_OBJECT_RANGE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/heap/heap-inl.h"
14
15namespace v8::internal {
16
18
20 : page_(page),
21 cells_(page->marking_bitmap()->cells()),
22 cage_base_(page->heap()->isolate()),
23 current_cell_index_(MarkingBitmap::IndexToCell(
24 MarkingBitmap::AddressToIndex(page->area_start()))),
25 current_cell_(cells_[current_cell_index_]) {
27}
28
30 AdvanceToNextValidObject();
31 return *this;
32}
33
35 iterator retval = *this;
36 ++(*this);
37 return retval;
38}
39
41 // If we found a regular object we are done. In case of free space, we
42 // need to continue.
43 //
44 // Reading the instance type of the map is safe here even in the presence
45 // of the mutator writing a new Map because Map objects are published with
46 // release stores (or are otherwise read-only) and the map is retrieved in
47 // `AdvanceToNextMarkedObject()` using an acquire load.
48 while (AdvanceToNextMarkedObject() &&
50 }
51}
52
54 // The following block moves the iterator to the next cell from the current
55 // object. This means skipping all possibly set mark bits (in case of black
56 // allocation).
57 if (!current_object_.is_null()) {
58 // Compute an end address that is inclusive. This allows clearing the cell
59 // up and including the end address. This works for one word fillers as
60 // well as other objects.
61 Address next_object = current_object_.address() + current_size_;
62 current_object_ = HeapObject();
63 if (MemoryChunk::IsAligned(next_object)) {
64 return false;
65 }
66 // Area end may not be exactly aligned to kAlignment. We don't need to bail
67 // out for area_end() though as we are guaranteed to have a bit for the
68 // whole page.
69 DCHECK_LE(next_object, page_->area_end());
70 // Move to the corresponding cell of the end index.
71 const auto next_markbit_index = MarkingBitmap::AddressToIndex(next_object);
72 DCHECK_GE(MarkingBitmap::IndexToCell(next_markbit_index),
73 current_cell_index_);
74 current_cell_index_ = MarkingBitmap::IndexToCell(next_markbit_index);
75 DCHECK_LT(current_cell_index_, MarkingBitmap::kCellsCount);
76 // Mask out lower addresses in the cell.
78 MarkingBitmap::IndexInCellMask(next_markbit_index);
79 current_cell_ = cells_[current_cell_index_] & ~(mask - 1);
80 }
81 // The next block finds any marked object starting from the current cell.
82 const MemoryChunk* chunk = page_->Chunk();
83 while (true) {
84 if (current_cell_) {
85 const auto trailing_zeros = base::bits::CountTrailingZeros(current_cell_);
86 Address current_cell_base =
87 chunk->address() + MarkingBitmap::CellToBase(current_cell_index_);
88 Address object_address = current_cell_base + trailing_zeros * kTaggedSize;
89 // The object may be a filler which we want to skip.
90 current_object_ = HeapObject::FromAddress(object_address);
91 current_map_ = current_object_->map(cage_base_, kAcquireLoad);
92 DCHECK(MapWord::IsMapOrForwarded(current_map_));
93 current_size_ = ALIGN_TO_ALLOCATION_ALIGNMENT(
94 current_object_->SizeFromMap(current_map_));
95 CHECK(page_->ContainsLimit(object_address + current_size_));
96 return true;
97 }
98 if (++current_cell_index_ >= MarkingBitmap::kCellsCount) break;
99 current_cell_ = cells_[current_cell_index_];
100 }
101 return false;
102}
103
105
107
108} // namespace v8::internal
109
110#endif // V8_HEAP_LIVE_OBJECT_RANGE_INL_H_
static Tagged< HeapObject > FromAddress(Address address)
const PageMetadata *const page_
static V8_EXPORT_PRIVATE bool IsMapOrForwarded(Tagged< Map > map)
Definition objects.cc:6701
uintptr_t CellType
Definition marking.h:21
static constexpr size_t kCellsCount
Definition marking.h:109
static V8_INLINE constexpr CellIndex IndexToCell(MarkBitIndex index)
Definition marking.h:119
static V8_INLINE constexpr MarkBitIndex AddressToIndex(Address address)
static V8_INLINE constexpr Address CellToBase(CellIndex cell_index)
Definition marking.h:127
static V8_INLINE constexpr CellType IndexInCellMask(MarkBitIndex index)
Definition marking.h:135
V8_INLINE Address address() const
static V8_INLINE constexpr bool IsAligned(Address address)
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
uint32_t const mask
constexpr unsigned CountTrailingZeros(T value)
Definition bits.h:144
V8_INLINE constexpr bool IsFreeSpaceOrFiller(InstanceType instance_type)
constexpr int kTaggedSize
Definition globals.h:542
static constexpr Address kNullAddress
Definition v8-internal.h:53
static constexpr AcquireLoadTag kAcquireLoad
Definition globals.h:2908
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489