blob: 61292bf562dad03ce63d59c65c8eb14e77520d90 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
10namespace v8 {
11namespace internal {
12
13RootIndexMap::RootIndexMap(Isolate* isolate) {
14 map_ = isolate->root_index_map();
15 if (map_ != NULL) return;
Ben Murdoch61f157c2016-09-16 13:49:30 +010016 map_ = new base::HashMap(base::HashMap::PointersMatch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000017 for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) {
18 Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
19 Object* root = isolate->heap()->root(root_index);
Ben Murdoch097c5b22016-05-18 11:27:45 +010020 if (!root->IsHeapObject()) continue;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000021 // Omit root entries that can be written after initialization. They must
22 // not be referenced through the root list in the snapshot.
Ben Murdoch097c5b22016-05-18 11:27:45 +010023 if (isolate->heap()->RootCanBeTreatedAsConstant(root_index)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024 HeapObject* heap_object = HeapObject::cast(root);
Ben Murdoch61f157c2016-09-16 13:49:30 +010025 base::HashMap::Entry* entry = LookupEntry(map_, heap_object, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 if (entry != NULL) {
27 // Some are initialized to a previous value in the root list.
28 DCHECK_LT(GetValue(entry), i);
29 } else {
30 SetValue(LookupEntry(map_, heap_object, true), i);
31 }
Ben Murdoch097c5b22016-05-18 11:27:45 +010032 } else {
33 // Immortal immovable root objects are constant and allocated on the first
34 // page of old space. Non-constant roots cannot be immortal immovable. The
35 // root index map contains all immortal immmovable root objects.
36 CHECK(!Heap::RootIsImmortalImmovable(root_index));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000037 }
38 }
39 isolate->set_root_index_map(map_);
40}
41
42} // namespace internal
43} // namespace v8