OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The common functionality when building with or without snapshots. | 5 // The common functionality when building with or without snapshots. |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
11 #include "src/serialize.h" | 11 #include "src/serialize.h" |
12 #include "src/snapshot.h" | 12 #include "src/snapshot.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) { | |
18 deserializer->AddReservation(NEW_SPACE, new_space_used_); | |
19 deserializer->AddReservation(OLD_POINTER_SPACE, pointer_space_used_); | |
20 deserializer->AddReservation(OLD_DATA_SPACE, data_space_used_); | |
21 deserializer->AddReservation(CODE_SPACE, code_space_used_); | |
22 deserializer->AddReservation(MAP_SPACE, map_space_used_); | |
23 deserializer->AddReservation(CELL_SPACE, cell_space_used_); | |
24 deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_space_used_); | |
25 deserializer->AddReservation(LO_SPACE, lo_space_used_); | |
26 } | |
27 | |
28 | 17 |
29 bool Snapshot::Initialize(Isolate* isolate) { | 18 bool Snapshot::Initialize(Isolate* isolate) { |
30 if (size_ > 0) { | 19 if (size_ > 0) { |
31 base::ElapsedTimer timer; | 20 base::ElapsedTimer timer; |
32 if (FLAG_profile_deserialization) { | 21 if (FLAG_profile_deserialization) timer.Start(); |
33 timer.Start(); | 22 |
34 } | 23 SnapshotData snapshot_data(data_, size_); |
35 SnapshotByteSource source(raw_data_, raw_size_); | 24 Deserializer deserializer(&snapshot_data); |
36 Deserializer deserializer(&source); | |
37 ReserveSpaceForLinkedInSnapshot(&deserializer); | |
38 bool success = isolate->Init(&deserializer); | 25 bool success = isolate->Init(&deserializer); |
39 if (FLAG_profile_deserialization) { | 26 if (FLAG_profile_deserialization) { |
40 double ms = timer.Elapsed().InMillisecondsF(); | 27 double ms = timer.Elapsed().InMillisecondsF(); |
41 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); | 28 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); |
42 } | 29 } |
43 return success; | 30 return success; |
44 } | 31 } |
45 return false; | 32 return false; |
46 } | 33 } |
47 | 34 |
48 | 35 |
49 bool Snapshot::HaveASnapshotToStartFrom() { | 36 bool Snapshot::HaveASnapshotToStartFrom() { |
50 return size_ != 0; | 37 return size_ != 0; |
51 } | 38 } |
52 | 39 |
53 | 40 |
54 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { | 41 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { |
55 if (context_size_ == 0) { | 42 if (context_size_ == 0) return Handle<Context>(); |
56 return Handle<Context>(); | 43 |
57 } | 44 SnapshotData snapshot_data(context_data_, context_size_); |
58 SnapshotByteSource source(context_raw_data_, | 45 Deserializer deserializer(&snapshot_data); |
59 context_raw_size_); | |
60 Deserializer deserializer(&source); | |
61 Object* root; | 46 Object* root; |
62 deserializer.AddReservation(NEW_SPACE, context_new_space_used_); | |
63 deserializer.AddReservation(OLD_POINTER_SPACE, context_pointer_space_used_); | |
64 deserializer.AddReservation(OLD_DATA_SPACE, context_data_space_used_); | |
65 deserializer.AddReservation(CODE_SPACE, context_code_space_used_); | |
66 deserializer.AddReservation(MAP_SPACE, context_map_space_used_); | |
67 deserializer.AddReservation(CELL_SPACE, context_cell_space_used_); | |
68 deserializer.AddReservation(PROPERTY_CELL_SPACE, | |
69 context_property_cell_space_used_); | |
70 deserializer.AddReservation(LO_SPACE, context_lo_space_used_); | |
71 deserializer.DeserializePartial(isolate, &root); | 47 deserializer.DeserializePartial(isolate, &root); |
72 CHECK(root->IsContext()); | 48 CHECK(root->IsContext()); |
73 return Handle<Context>(Context::cast(root)); | 49 return Handle<Context>(Context::cast(root)); |
74 } | 50 } |
75 | 51 |
76 | 52 |
77 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 53 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
78 // Dummy implementations of Set*FromFile(..) APIs. | 54 // Dummy implementations of Set*FromFile(..) APIs. |
79 // | 55 // |
80 // These are meant for use with snapshot-external.cc. Should this file | 56 // These are meant for use with snapshot-external.cc. Should this file |
81 // be compiled with those options we just supply these dummy implementations | 57 // be compiled with those options we just supply these dummy implementations |
82 // below. This happens when compiling the mksnapshot utility. | 58 // below. This happens when compiling the mksnapshot utility. |
83 void SetNativesFromFile(StartupData* data) { CHECK(false); } | 59 void SetNativesFromFile(StartupData* data) { CHECK(false); } |
84 void SetSnapshotFromFile(StartupData* data) { CHECK(false); } | 60 void SetSnapshotFromFile(StartupData* data) { CHECK(false); } |
85 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 61 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
86 | 62 |
87 } } // namespace v8::internal | 63 } } // namespace v8::internal |
OLD | NEW |