v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
address-map.cc
Go to the documentation of this file.
1// Copyright 2015 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
9
10namespace v8 {
11namespace internal {
12
14 map_ = isolate->root_index_map();
15 if (map_ != nullptr) return;
18 root_index <= RootIndex::kLastStrongOrReadOnlyRoot; ++root_index) {
19 Tagged<Object> root = isolate->root(root_index);
20 if (!IsHeapObject(root)) continue;
21 // Omit root entries that can be written after initialization. They must
22 // not be referenced through the root list in the snapshot.
23 // Since we map the raw address of an root item to its root list index, the
24 // raw address must be constant, i.e. the object must be immovable.
25 if (RootsTable::IsImmortalImmovable(root_index)) {
26 Tagged<HeapObject> heap_object = Cast<HeapObject>(root);
27 Maybe<uint32_t> maybe_index = map_->Get(heap_object);
28 uint32_t index = static_cast<uint32_t>(root_index);
29 if (maybe_index.IsJust()) {
30 // Some are initialized to a previous value in the root list.
31 DCHECK_LT(maybe_index.FromJust(), index);
32 } else {
33 map_->Set(heap_object, index);
34 }
35 }
36 }
37 isolate->set_root_index_map(map_);
38}
39
40} // namespace internal
41} // namespace v8
V8_INLINE bool IsJust() const
Definition v8-maybe.h:36
V8_INLINE T FromJust() const &
Definition v8-maybe.h:64
void Set(Type value, uint32_t index)
Definition address-map.h:24
Maybe< uint32_t > Get(Type value) const
Definition address-map.h:29
RootIndexMap(Isolate *isolate)
HeapObjectToIndexHashMap * map_
Definition address-map.h:75
static constexpr bool IsImmortalImmovable(RootIndex root_index)
Definition roots.h:616
V8_INLINE constexpr bool IsHeapObject(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:669
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK_LT(v1, v2)
Definition logging.h:489