OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Used for building with external snapshots. | |
6 | |
7 #include "v8.h" | |
Benedikt Meurer
2014/05/27 04:09:59
Nit: No new v8.h includes if possible.
vogelheim
2014/05/27 15:20:23
Well, I tried, but this uses V8::Initialize(Deseri
Benedikt Meurer
2014/05/29 03:19:59
I see, in that case we'll have to keep that v8.h i
| |
8 | |
9 #include "serialize.h" | |
10 #include "snapshot.h" | |
11 #include "snapshot-source-sink.h" | |
12 | |
13 namespace v8 { | |
14 namespace internal { | |
15 | |
16 | |
17 class SnapshotImpl { | |
jochen (gone - plz use gerrit)
2014/05/26 14:34:49
should be a struct (and use e.g. data_ instead of
vogelheim
2014/05/27 15:20:23
Done.
| |
18 public: | |
19 const byte* data_; | |
20 int size_; | |
21 int new_space_used_; | |
22 int pointer_space_used_; | |
23 int data_space_used_; | |
24 int code_space_used_; | |
25 int map_space_used_; | |
26 int cell_space_used_; | |
27 int property_cell_space_used_; | |
28 | |
29 const byte* context_data_; | |
30 int context_size_; | |
31 int context_new_space_used_; | |
32 int context_pointer_space_used_; | |
33 int context_data_space_used_; | |
34 int context_code_space_used_; | |
35 int context_map_space_used_; | |
36 int context_cell_space_used_; | |
37 int context_property_cell_space_used_; | |
38 | |
39 static SnapshotImpl* impl_; | |
jochen (gone - plz use gerrit)
2014/05/26 14:34:49
and this should be moved out of SnapshotImpl
vogelheim
2014/05/27 15:20:23
Done.
| |
40 }; | |
41 | |
42 | |
43 SnapshotImpl* SnapshotImpl::impl_ = NULL; | |
44 | |
45 | |
46 bool Snapshot::HaveASnapshotToStartFrom() { | |
47 return SnapshotImpl::impl_ != NULL; | |
48 } | |
49 | |
50 | |
51 bool Snapshot::IsEnabled() { | |
52 return HaveASnapshotToStartFrom(); | |
53 } | |
54 | |
55 | |
56 bool Snapshot::Initialize() { | |
57 if (!HaveASnapshotToStartFrom()) | |
58 return false; | |
59 | |
60 ElapsedTimer timer; | |
61 if (FLAG_profile_deserialization) { | |
62 timer.Start(); | |
63 } | |
64 SnapshotByteSource source(SnapshotImpl::impl_->data_, | |
65 SnapshotImpl::impl_->size_); | |
66 Deserializer deserializer(&source); | |
67 deserializer.set_reservation(NEW_SPACE, | |
68 SnapshotImpl::impl_->new_space_used_); | |
69 deserializer.set_reservation(OLD_POINTER_SPACE, | |
70 SnapshotImpl::impl_->pointer_space_used_); | |
71 deserializer.set_reservation(OLD_DATA_SPACE, | |
72 SnapshotImpl::impl_->data_space_used_); | |
73 deserializer.set_reservation(CODE_SPACE, | |
74 SnapshotImpl::impl_->code_space_used_); | |
75 deserializer.set_reservation(MAP_SPACE, | |
76 SnapshotImpl::impl_->map_space_used_); | |
77 deserializer.set_reservation(CELL_SPACE, | |
78 SnapshotImpl::impl_->cell_space_used_); | |
79 deserializer.set_reservation(PROPERTY_CELL_SPACE, | |
80 SnapshotImpl::impl_->property_cell_space_used_); | |
81 bool success = V8::Initialize(&deserializer); | |
82 if (FLAG_profile_deserialization) { | |
83 double ms = timer.Elapsed().InMillisecondsF(); | |
84 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); | |
85 } | |
86 return success; | |
87 } | |
88 | |
89 | |
90 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { | |
91 if (!HaveASnapshotToStartFrom()) | |
92 return Handle<Context>(); | |
93 | |
94 SnapshotByteSource source(SnapshotImpl::impl_->context_data_, | |
95 SnapshotImpl::impl_->context_size_); | |
96 Deserializer deserializer(&source); | |
97 deserializer.set_reservation(NEW_SPACE, | |
98 SnapshotImpl::impl_->context_new_space_used_); | |
99 deserializer.set_reservation(OLD_POINTER_SPACE, | |
100 SnapshotImpl::impl_-> | |
101 context_pointer_space_used_); | |
102 deserializer.set_reservation(OLD_DATA_SPACE, | |
103 SnapshotImpl::impl_->context_data_space_used_); | |
104 deserializer.set_reservation(CODE_SPACE, | |
105 SnapshotImpl::impl_->context_code_space_used_); | |
106 deserializer.set_reservation(MAP_SPACE, | |
107 SnapshotImpl::impl_->context_map_space_used_); | |
108 deserializer.set_reservation(CELL_SPACE, | |
109 SnapshotImpl::impl_->context_cell_space_used_); | |
110 deserializer.set_reservation(PROPERTY_CELL_SPACE, | |
111 SnapshotImpl::impl_-> | |
112 context_property_cell_space_used_); | |
113 Object* root; | |
114 deserializer.DeserializePartial(isolate, &root); | |
115 CHECK(root->IsContext()); | |
116 return Handle<Context>(Context::cast(root)); | |
117 } | |
118 | |
119 | |
120 void SetSnapshotFromFile(StartupData* snapshot_blob) { | |
121 ASSERT(snapshot_blob); | |
122 ASSERT(snapshot_blob->data); | |
123 ASSERT(snapshot_blob->raw_size > 0); | |
124 | |
125 SnapshotImpl::impl_ = new SnapshotImpl; | |
126 SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), | |
127 snapshot_blob->raw_size); | |
128 | |
129 bool success = source.GetBlob(&SnapshotImpl::impl_->data_, | |
130 &SnapshotImpl::impl_->size_); | |
131 SnapshotImpl::impl_->new_space_used_ = source.GetInt(); | |
132 SnapshotImpl::impl_->pointer_space_used_ = source.GetInt(); | |
133 SnapshotImpl::impl_->data_space_used_ = source.GetInt(); | |
134 SnapshotImpl::impl_->code_space_used_ = source.GetInt(); | |
135 SnapshotImpl::impl_->map_space_used_ = source.GetInt(); | |
136 SnapshotImpl::impl_->cell_space_used_ = source.GetInt(); | |
137 SnapshotImpl::impl_->property_cell_space_used_ = source.GetInt(); | |
138 | |
139 success &= source.GetBlob(&SnapshotImpl::impl_->context_data_, | |
140 &SnapshotImpl::impl_->context_size_); | |
141 SnapshotImpl::impl_->context_new_space_used_ = source.GetInt(); | |
142 SnapshotImpl::impl_->context_pointer_space_used_ = source.GetInt(); | |
143 SnapshotImpl::impl_->context_data_space_used_ = source.GetInt(); | |
144 SnapshotImpl::impl_->context_code_space_used_ = source.GetInt(); | |
145 SnapshotImpl::impl_->context_map_space_used_ = source.GetInt(); | |
146 SnapshotImpl::impl_->context_cell_space_used_ = source.GetInt(); | |
147 SnapshotImpl::impl_->context_property_cell_space_used_ = source.GetInt(); | |
148 | |
149 ASSERT(success); | |
150 } | |
151 | |
152 } } // namespace v8::internal | |
OLD | NEW |