Line data Source code
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 :
5 : #include "src/address-map.h"
6 : #include "src/heap/heap.h"
7 : #include "src/isolate.h"
8 : #include "src/objects-inl.h"
9 : #include "src/objects/heap-object-inl.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 668098 : RootIndexMap::RootIndexMap(Isolate* isolate) {
15 668098 : map_ = isolate->root_index_map();
16 668098 : if (map_ != nullptr) return;
17 34446 : map_ = new HeapObjectToIndexHashMap();
18 : for (RootIndex root_index = RootIndex::kFirstStrongOrReadOnlyRoot;
19 10174389 : root_index <= RootIndex::kLastStrongOrReadOnlyRoot; ++root_index) {
20 : Object root = isolate->root(root_index);
21 10157167 : if (!root->IsHeapObject()) continue;
22 : // Omit root entries that can be written after initialization. They must
23 : // not be referenced through the root list in the snapshot.
24 : // Since we map the raw address of an root item to its root list index, the
25 : // raw address must be constant, i.e. the object must be immovable.
26 10157147 : if (RootsTable::IsImmortalImmovable(root_index)) {
27 : HeapObject heap_object = HeapObject::cast(root);
28 9829956 : Maybe<uint32_t> maybe_index = map_->Get(heap_object);
29 9829906 : uint32_t index = static_cast<uint32_t>(root_index);
30 9829906 : if (maybe_index.IsJust()) {
31 : // Some are initialized to a previous value in the root list.
32 : DCHECK_LT(maybe_index.FromJust(), index);
33 : } else {
34 9829794 : map_->Set(heap_object, index);
35 : }
36 : }
37 : }
38 17222 : isolate->set_root_index_map(map_);
39 : }
40 :
41 241525544 : bool RootIndexMap::Lookup(Address obj, RootIndex* out_root_list) const {
42 241525544 : return Lookup(HeapObject::cast(Object(obj)), out_root_list);
43 : }
44 :
45 : } // namespace internal
46 122036 : } // namespace v8
|