V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
read-only-deserializer.cc
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 void ReadOnlyDeserializer::DeserializeInto(Isolate* isolate) {
17  Initialize(isolate);
18 
19  if (!allocator()->ReserveSpace()) {
20  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  ReadOnlyRoots(isolate).Iterate(this);
37  isolate->heap()->read_only_space()->RepairFreeListsAfterDeserialization();
38 
39  // Deserialize the Read-only Object Cache.
40  std::vector<Object*>* cache = isolate->read_only_object_cache();
41  for (size_t i = 0;; ++i) {
42  // Extend the array ready to get a value when deserializing.
43  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  ObjectSlot(&cache->at(i)));
48  if (cache->at(i)->IsUndefined(isolate)) break;
49  }
50  DeserializeDeferredObjects();
51  }
52 }
53 
54 void ReadOnlyDeserializer::RehashHeap() {
55  DCHECK(FLAG_rehash_snapshot && can_rehash());
56  Rehash();
57 }
58 
59 } // namespace internal
60 } // namespace v8
Definition: libplatform.h:13