V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
startup-deserializer.cc
1 // Copyright 2017 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/startup-deserializer.h"
6 
7 #include "src/api.h"
8 #include "src/assembler-inl.h"
9 #include "src/code-stubs.h"
10 #include "src/heap/heap-inl.h"
11 #include "src/snapshot/read-only-deserializer.h"
12 #include "src/snapshot/snapshot.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 void StartupDeserializer::DeserializeInto(Isolate* isolate) {
18  Initialize(isolate);
19 
20  ReadOnlyDeserializer read_only_deserializer(read_only_data_);
21  read_only_deserializer.SetRehashability(can_rehash());
22  read_only_deserializer.DeserializeInto(isolate);
23 
24  if (!allocator()->ReserveSpace()) {
25  V8::FatalProcessOutOfMemory(isolate, "StartupDeserializer");
26  }
27 
28  // No active threads.
29  DCHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
30  // No active handles.
31  DCHECK(isolate->handle_scope_implementer()->blocks()->empty());
32  // Partial snapshot cache is not yet populated.
33  DCHECK(isolate->partial_snapshot_cache()->empty());
34  // Builtins are not yet created.
35  DCHECK(!isolate->builtins()->is_initialized());
36 
37  {
38  DisallowHeapAllocation no_gc;
39  isolate->heap()->IterateSmiRoots(this);
40  isolate->heap()->IterateStrongRoots(this, VISIT_FOR_SERIALIZATION);
41  Iterate(isolate, this);
42  isolate->heap()->IterateWeakRoots(this, VISIT_FOR_SERIALIZATION);
43  DeserializeDeferredObjects();
44  RestoreExternalReferenceRedirectors(accessor_infos());
45  RestoreExternalReferenceRedirectors(call_handler_infos());
46 
47  // Flush the instruction cache for the entire code-space. Must happen after
48  // builtins deserialization.
49  FlushICache();
50  }
51 
52  isolate->heap()->set_native_contexts_list(
53  ReadOnlyRoots(isolate).undefined_value());
54  // The allocation site list is build during root iteration, but if no sites
55  // were encountered then it needs to be initialized to undefined.
56  if (isolate->heap()->allocation_sites_list() == Smi::kZero) {
57  isolate->heap()->set_allocation_sites_list(
58  ReadOnlyRoots(isolate).undefined_value());
59  }
60 
61 
62  isolate->builtins()->MarkInitialized();
63 
64  LogNewMapEvents();
65 
66  if (FLAG_rehash_snapshot && can_rehash()) {
67  isolate->heap()->InitializeHashSeed();
68  read_only_deserializer.RehashHeap();
69  Rehash();
70  }
71 }
72 
73 void StartupDeserializer::LogNewMapEvents() {
74  if (FLAG_trace_maps) LOG(isolate_, LogAllMaps());
75 }
76 
77 void StartupDeserializer::FlushICache() {
78  DCHECK(!deserializing_user_code());
79  // The entire isolate is newly deserialized. Simply flush all code pages.
80  for (Page* p : *isolate()->heap()->code_space()) {
81  Assembler::FlushICache(p->area_start(), p->area_end() - p->area_start());
82  }
83 }
84 
85 } // namespace internal
86 } // namespace v8
Definition: libplatform.h:13