Line data Source code
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/heap/heap-inl.h"
10 : #include "src/snapshot/read-only-deserializer.h"
11 : #include "src/snapshot/snapshot.h"
12 : #include "src/v8threads.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 60993 : void StartupDeserializer::DeserializeInto(Isolate* isolate) {
18 182979 : Initialize(isolate);
19 :
20 60993 : ReadOnlyDeserializer read_only_deserializer(read_only_data_);
21 : read_only_deserializer.SetRehashability(can_rehash());
22 60993 : read_only_deserializer.DeserializeInto(isolate);
23 :
24 60993 : if (!allocator()->ReserveSpace()) {
25 0 : 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 60993 : isolate->heap()->IterateSmiRoots(this);
40 60993 : isolate->heap()->IterateStrongRoots(this, VISIT_FOR_SERIALIZATION);
41 60993 : Iterate(isolate, this);
42 60993 : isolate->heap()->IterateWeakRoots(this, VISIT_FOR_SERIALIZATION);
43 60993 : DeserializeDeferredObjects();
44 60992 : RestoreExternalReferenceRedirectors(accessor_infos());
45 60992 : RestoreExternalReferenceRedirectors(call_handler_infos());
46 :
47 : // Flush the instruction cache for the entire code-space. Must happen after
48 : // builtins deserialization.
49 60992 : 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 60992 : 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 60993 : LogNewMapEvents();
65 :
66 121986 : if (FLAG_rehash_snapshot && can_rehash()) {
67 60933 : isolate->heap()->InitializeHashSeed();
68 60933 : read_only_deserializer.RehashHeap();
69 60933 : Rehash();
70 : }
71 60993 : }
72 :
73 60993 : void StartupDeserializer::LogNewMapEvents() {
74 60993 : if (FLAG_trace_maps) LOG(isolate_, LogAllMaps());
75 60993 : }
76 :
77 60993 : void StartupDeserializer::FlushICache() {
78 : DCHECK(!deserializing_user_code());
79 : // The entire isolate is newly deserialized. Simply flush all code pages.
80 182978 : for (Page* p : *isolate()->heap()->code_space()) {
81 60993 : FlushInstructionCache(p->area_start(), p->area_end() - p->area_start());
82 : }
83 60992 : }
84 :
85 : } // namespace internal
86 178779 : } // namespace v8
|