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/snapshot.h"
11 : #include "src/v8threads.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 62385 : void StartupDeserializer::DeserializeInto(Isolate* isolate) {
17 62385 : Initialize(isolate);
18 :
19 62385 : if (!allocator()->ReserveSpace()) {
20 0 : V8::FatalProcessOutOfMemory(isolate, "StartupDeserializer");
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->partial_snapshot_cache()->empty());
29 : // Builtins are not yet created.
30 : DCHECK(!isolate->builtins()->is_initialized());
31 :
32 : {
33 : DisallowHeapAllocation no_gc;
34 124772 : isolate->heap()->IterateSmiRoots(this);
35 62386 : isolate->heap()->IterateStrongRoots(this, VISIT_FOR_SERIALIZATION);
36 62386 : Iterate(isolate, this);
37 62386 : isolate->heap()->IterateWeakRoots(this, VISIT_FOR_SERIALIZATION);
38 62385 : DeserializeDeferredObjects();
39 62385 : RestoreExternalReferenceRedirectors(accessor_infos());
40 62386 : RestoreExternalReferenceRedirectors(call_handler_infos());
41 :
42 : // Flush the instruction cache for the entire code-space. Must happen after
43 : // builtins deserialization.
44 62385 : FlushICache();
45 : }
46 :
47 : isolate->heap()->set_native_contexts_list(
48 : ReadOnlyRoots(isolate).undefined_value());
49 : // The allocation site list is build during root iteration, but if no sites
50 : // were encountered then it needs to be initialized to undefined.
51 62386 : if (isolate->heap()->allocation_sites_list() == Smi::kZero) {
52 : isolate->heap()->set_allocation_sites_list(
53 : ReadOnlyRoots(isolate).undefined_value());
54 : }
55 :
56 :
57 : isolate->builtins()->MarkInitialized();
58 :
59 62386 : LogNewMapEvents();
60 :
61 62386 : if (FLAG_rehash_snapshot && can_rehash()) {
62 : // Hash seed was initalized in ReadOnlyDeserializer.
63 62326 : Rehash();
64 : }
65 62386 : }
66 :
67 62386 : void StartupDeserializer::LogNewMapEvents() {
68 62386 : if (FLAG_trace_maps) LOG(isolate_, LogAllMaps());
69 62386 : }
70 :
71 62386 : void StartupDeserializer::FlushICache() {
72 : DCHECK(!deserializing_user_code());
73 : // The entire isolate is newly deserialized. Simply flush all code pages.
74 124772 : for (Page* p : *isolate()->heap()->code_space()) {
75 62386 : FlushInstructionCache(p->area_start(), p->area_end() - p->area_start());
76 : }
77 62386 : }
78 :
79 : } // namespace internal
80 122036 : } // namespace v8
|