OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/snapshot/code-serializer.h" | 5 #include "src/snapshot/code-serializer.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/log.h" | 8 #include "src/log.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/snapshot/deserializer.h" | 10 #include "src/snapshot/deserializer.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // Serialize code object. | 28 // Serialize code object. |
29 SnapshotByteSink sink(info->code()->CodeSize() * 2); | 29 SnapshotByteSink sink(info->code()->CodeSize() * 2); |
30 CodeSerializer cs(isolate, &sink, *source); | 30 CodeSerializer cs(isolate, &sink, *source); |
31 DisallowHeapAllocation no_gc; | 31 DisallowHeapAllocation no_gc; |
32 Object** location = Handle<Object>::cast(info).location(); | 32 Object** location = Handle<Object>::cast(info).location(); |
33 cs.VisitPointer(location); | 33 cs.VisitPointer(location); |
34 cs.SerializeDeferredObjects(); | 34 cs.SerializeDeferredObjects(); |
35 cs.Pad(); | 35 cs.Pad(); |
36 | 36 |
37 SerializedCodeData data(sink.data(), cs); | 37 SerializedCodeData data(sink.data(), &cs); |
38 ScriptData* script_data = data.GetScriptData(); | 38 ScriptData* script_data = data.GetScriptData(); |
39 | 39 |
40 if (FLAG_profile_deserialization) { | 40 if (FLAG_profile_deserialization) { |
41 double ms = timer.Elapsed().InMillisecondsF(); | 41 double ms = timer.Elapsed().InMillisecondsF(); |
42 int length = script_data->length(); | 42 int length = script_data->length(); |
43 PrintF("[Serializing to %d bytes took %0.3f ms]\n", length, ms); | 43 PrintF("[Serializing to %d bytes took %0.3f ms]\n", length, ms); |
44 } | 44 } |
45 | 45 |
46 return script_data; | 46 return script_data; |
47 } | 47 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 uint32_t a() const { return a_; } | 228 uint32_t a() const { return a_; } |
229 uint32_t b() const { return b_; } | 229 uint32_t b() const { return b_; } |
230 | 230 |
231 private: | 231 private: |
232 uint32_t a_; | 232 uint32_t a_; |
233 uint32_t b_; | 233 uint32_t b_; |
234 | 234 |
235 DISALLOW_COPY_AND_ASSIGN(Checksum); | 235 DISALLOW_COPY_AND_ASSIGN(Checksum); |
236 }; | 236 }; |
237 | 237 |
238 SerializedCodeData::SerializedCodeData(const List<byte>& payload, | 238 SerializedCodeData::SerializedCodeData(const List<byte>* payload, |
239 const CodeSerializer& cs) { | 239 const CodeSerializer* cs) { |
240 DisallowHeapAllocation no_gc; | 240 DisallowHeapAllocation no_gc; |
241 const List<uint32_t>* stub_keys = cs.stub_keys(); | 241 const List<uint32_t>* stub_keys = cs->stub_keys(); |
242 | 242 |
243 List<Reservation> reservations; | 243 List<Reservation> reservations; |
244 cs.EncodeReservations(&reservations); | 244 cs->EncodeReservations(&reservations); |
245 | 245 |
246 // Calculate sizes. | 246 // Calculate sizes. |
247 int reservation_size = reservations.length() * kInt32Size; | 247 int reservation_size = reservations.length() * kInt32Size; |
248 int num_stub_keys = stub_keys->length(); | 248 int num_stub_keys = stub_keys->length(); |
249 int stub_keys_size = stub_keys->length() * kInt32Size; | 249 int stub_keys_size = stub_keys->length() * kInt32Size; |
250 int payload_offset = kHeaderSize + reservation_size + stub_keys_size; | 250 int payload_offset = kHeaderSize + reservation_size + stub_keys_size; |
251 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); | 251 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); |
252 int size = padded_payload_offset + payload.length(); | 252 int size = padded_payload_offset + payload->length(); |
253 | 253 |
254 // Allocate backing store and create result data. | 254 // Allocate backing store and create result data. |
255 AllocateData(size); | 255 AllocateData(size); |
256 | 256 |
257 // Set header values. | 257 // Set header values. |
258 SetMagicNumber(cs.isolate()); | 258 SetMagicNumber(cs->isolate()); |
259 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 259 SetHeaderValue(kVersionHashOffset, Version::Hash()); |
260 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); | 260 SetHeaderValue(kSourceHashOffset, SourceHash(cs->source())); |
261 SetHeaderValue(kCpuFeaturesOffset, | 261 SetHeaderValue(kCpuFeaturesOffset, |
262 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); | 262 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); |
263 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); | 263 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); |
264 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 264 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
265 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); | 265 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); |
266 SetHeaderValue(kPayloadLengthOffset, payload.length()); | 266 SetHeaderValue(kPayloadLengthOffset, payload->length()); |
267 | 267 |
268 Checksum checksum(payload.ToConstVector()); | 268 Checksum checksum(payload->ToConstVector()); |
269 SetHeaderValue(kChecksum1Offset, checksum.a()); | 269 SetHeaderValue(kChecksum1Offset, checksum.a()); |
270 SetHeaderValue(kChecksum2Offset, checksum.b()); | 270 SetHeaderValue(kChecksum2Offset, checksum.b()); |
271 | 271 |
272 // Copy reservation chunk sizes. | 272 // Copy reservation chunk sizes. |
273 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 273 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
274 reservation_size); | 274 reservation_size); |
275 | 275 |
276 // Copy code stub keys. | 276 // Copy code stub keys. |
277 CopyBytes(data_ + kHeaderSize + reservation_size, | 277 CopyBytes(data_ + kHeaderSize + reservation_size, |
278 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); | 278 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); |
279 | 279 |
280 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); | 280 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); |
281 | 281 |
282 // Copy serialized data. | 282 // Copy serialized data. |
283 CopyBytes(data_ + padded_payload_offset, payload.begin(), | 283 CopyBytes(data_ + padded_payload_offset, payload->begin(), |
284 static_cast<size_t>(payload.length())); | 284 static_cast<size_t>(payload->length())); |
285 } | 285 } |
286 | 286 |
287 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( | 287 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( |
288 Isolate* isolate, String* source) const { | 288 Isolate* isolate, String* source) const { |
289 uint32_t magic_number = GetMagicNumber(); | 289 uint32_t magic_number = GetMagicNumber(); |
290 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; | 290 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; |
291 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); | 291 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); |
292 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); | 292 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); |
293 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); | 293 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); |
294 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); | 294 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 SanityCheckResult r = scd->SanityCheck(isolate, source); | 355 SanityCheckResult r = scd->SanityCheck(isolate, source); |
356 if (r == CHECK_SUCCESS) return scd; | 356 if (r == CHECK_SUCCESS) return scd; |
357 cached_data->Reject(); | 357 cached_data->Reject(); |
358 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 358 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
359 delete scd; | 359 delete scd; |
360 return NULL; | 360 return NULL; |
361 } | 361 } |
362 | 362 |
363 } // namespace internal | 363 } // namespace internal |
364 } // namespace v8 | 364 } // namespace v8 |
OLD | NEW |