Line data Source code
1 : // Copyright 2018 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/snapshot/read-only-deserializer.h"
6 :
7 : #include "src/api.h"
8 : #include "src/heap/heap-inl.h" // crbug.com/v8/8499
9 : #include "src/objects/slots.h"
10 : #include "src/snapshot/snapshot.h"
11 : #include "src/v8threads.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 62827 : void ReadOnlyDeserializer::DeserializeInto(Isolate* isolate) {
17 62827 : Initialize(isolate);
18 :
19 62827 : if (!allocator()->ReserveSpace()) {
20 0 : V8::FatalProcessOutOfMemory(isolate, "ReadOnlyDeserializer");
21 : }
22 :
23 : // No active threads.
24 : DCHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
25 : // No active handles.
26 : DCHECK(isolate->handle_scope_implementer()->blocks()->empty());
27 : // Partial snapshot cache is not yet populated.
28 : DCHECK(isolate->read_only_object_cache()->empty());
29 : DCHECK(isolate->partial_snapshot_cache()->empty());
30 : // Builtins are not yet created.
31 : DCHECK(!isolate->builtins()->is_initialized());
32 :
33 : {
34 : DisallowHeapAllocation no_gc;
35 :
36 125654 : ReadOnlyRoots(isolate).Iterate(this);
37 62827 : isolate->heap()->read_only_space()->RepairFreeListsAfterDeserialization();
38 :
39 : // Deserialize the Read-only Object Cache.
40 62827 : std::vector<Object>* cache = isolate->read_only_object_cache();
41 14010266 : for (size_t i = 0;; ++i) {
42 : // Extend the array ready to get a value when deserializing.
43 14073093 : if (cache->size() <= i) cache->push_back(Smi::kZero);
44 : // During deserialization, the visitor populates the read-only object
45 : // cache and eventually terminates the cache with undefined.
46 : VisitRootPointer(Root::kReadOnlyObjectCache, nullptr,
47 28146198 : FullObjectSlot(&cache->at(i)));
48 14073093 : if (cache->at(i)->IsUndefined(isolate)) break;
49 14010266 : }
50 62827 : DeserializeDeferredObjects();
51 : }
52 62827 : }
53 :
54 62767 : void ReadOnlyDeserializer::RehashHeap() {
55 : DCHECK(FLAG_rehash_snapshot && can_rehash());
56 62767 : Rehash();
57 62767 : }
58 :
59 : } // namespace internal
60 183867 : } // namespace v8
|