OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2468 | 2468 |
2469 // Calculate sizes. | 2469 // Calculate sizes. |
2470 int reservation_size = reservations.length() * kInt32Size; | 2470 int reservation_size = reservations.length() * kInt32Size; |
2471 int size = kHeaderSize + reservation_size + payload.length(); | 2471 int size = kHeaderSize + reservation_size + payload.length(); |
2472 | 2472 |
2473 // Allocate backing store and create result data. | 2473 // Allocate backing store and create result data. |
2474 AllocateData(size); | 2474 AllocateData(size); |
2475 | 2475 |
2476 // Set header values. | 2476 // Set header values. |
2477 SetHeaderValue(kCheckSumOffset, Version::Hash()); | 2477 SetHeaderValue(kCheckSumOffset, Version::Hash()); |
2478 SetHeaderValue(kReservationsOffset, reservations.length()); | 2478 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
2479 SetHeaderValue(kPayloadLengthOffset, payload.length()); | 2479 SetHeaderValue(kPayloadLengthOffset, payload.length()); |
2480 | 2480 |
2481 // Copy reservation chunk sizes. | 2481 // Copy reservation chunk sizes. |
2482 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 2482 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
2483 reservation_size); | 2483 reservation_size); |
2484 | 2484 |
2485 // Copy serialized data. | 2485 // Copy serialized data. |
2486 CopyBytes(data_ + kHeaderSize + reservation_size, payload.begin(), | 2486 CopyBytes(data_ + kHeaderSize + reservation_size, payload.begin(), |
2487 static_cast<size_t>(payload.length())); | 2487 static_cast<size_t>(payload.length())); |
2488 } | 2488 } |
2489 | 2489 |
2490 | 2490 |
2491 bool SnapshotData::IsSane() { | 2491 bool SnapshotData::IsSane() { |
2492 return GetHeaderValue(kCheckSumOffset) == Version::Hash(); | 2492 return GetHeaderValue(kCheckSumOffset) == Version::Hash(); |
2493 } | 2493 } |
2494 | 2494 |
2495 | 2495 |
2496 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { | 2496 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { |
2497 return Vector<const Reservation>( | 2497 return Vector<const Reservation>( |
2498 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), | 2498 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), |
2499 GetHeaderValue(kReservationsOffset)); | 2499 GetHeaderValue(kNumReservationsOffset)); |
2500 } | 2500 } |
2501 | 2501 |
2502 | 2502 |
2503 Vector<const byte> SnapshotData::Payload() const { | 2503 Vector<const byte> SnapshotData::Payload() const { |
2504 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; | 2504 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
2505 const byte* payload = data_ + kHeaderSize + reservations_size; | 2505 const byte* payload = data_ + kHeaderSize + reservations_size; |
2506 int length = GetHeaderValue(kPayloadLengthOffset); | 2506 int length = GetHeaderValue(kPayloadLengthOffset); |
2507 DCHECK_EQ(data_ + size_, payload + length); | 2507 DCHECK_EQ(data_ + size_, payload + length); |
2508 return Vector<const byte>(payload, length); | 2508 return Vector<const byte>(payload, length); |
2509 } | 2509 } |
2510 | 2510 |
2511 | 2511 |
2512 class Checksum { | 2512 class Checksum { |
2513 public: | 2513 public: |
2514 explicit Checksum(Vector<const byte> payload) { | 2514 explicit Checksum(Vector<const byte> payload) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2549 DisallowHeapAllocation no_gc; | 2549 DisallowHeapAllocation no_gc; |
2550 const List<uint32_t>* stub_keys = cs.stub_keys(); | 2550 const List<uint32_t>* stub_keys = cs.stub_keys(); |
2551 | 2551 |
2552 List<Reservation> reservations; | 2552 List<Reservation> reservations; |
2553 cs.EncodeReservations(&reservations); | 2553 cs.EncodeReservations(&reservations); |
2554 | 2554 |
2555 // Calculate sizes. | 2555 // Calculate sizes. |
2556 int reservation_size = reservations.length() * kInt32Size; | 2556 int reservation_size = reservations.length() * kInt32Size; |
2557 int num_stub_keys = stub_keys->length(); | 2557 int num_stub_keys = stub_keys->length(); |
2558 int stub_keys_size = stub_keys->length() * kInt32Size; | 2558 int stub_keys_size = stub_keys->length() * kInt32Size; |
2559 int size = kHeaderSize + reservation_size + stub_keys_size + payload.length(); | 2559 int payload_offset = kHeaderSize + reservation_size + stub_keys_size; |
| 2560 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); |
| 2561 int size = padded_payload_offset + payload.length(); |
2560 | 2562 |
2561 // Allocate backing store and create result data. | 2563 // Allocate backing store and create result data. |
2562 AllocateData(size); | 2564 AllocateData(size); |
2563 | 2565 |
2564 // Set header values. | 2566 // Set header values. |
2565 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 2567 SetHeaderValue(kVersionHashOffset, Version::Hash()); |
2566 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); | 2568 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); |
2567 SetHeaderValue(kCpuFeaturesOffset, | 2569 SetHeaderValue(kCpuFeaturesOffset, |
2568 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); | 2570 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); |
2569 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); | 2571 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); |
2570 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings()); | 2572 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings()); |
2571 SetHeaderValue(kReservationsOffset, reservations.length()); | 2573 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
2572 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); | 2574 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); |
2573 SetHeaderValue(kPayloadLengthOffset, payload.length()); | 2575 SetHeaderValue(kPayloadLengthOffset, payload.length()); |
2574 | 2576 |
2575 Checksum checksum(payload.ToConstVector()); | 2577 Checksum checksum(payload.ToConstVector()); |
2576 SetHeaderValue(kChecksum1Offset, checksum.a()); | 2578 SetHeaderValue(kChecksum1Offset, checksum.a()); |
2577 SetHeaderValue(kChecksum2Offset, checksum.b()); | 2579 SetHeaderValue(kChecksum2Offset, checksum.b()); |
2578 | 2580 |
2579 // Copy reservation chunk sizes. | 2581 // Copy reservation chunk sizes. |
2580 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 2582 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
2581 reservation_size); | 2583 reservation_size); |
2582 | 2584 |
2583 // Copy code stub keys. | 2585 // Copy code stub keys. |
2584 CopyBytes(data_ + kHeaderSize + reservation_size, | 2586 CopyBytes(data_ + kHeaderSize + reservation_size, |
2585 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); | 2587 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); |
2586 | 2588 |
| 2589 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); |
| 2590 |
2587 // Copy serialized data. | 2591 // Copy serialized data. |
2588 CopyBytes(data_ + kHeaderSize + reservation_size + stub_keys_size, | 2592 CopyBytes(data_ + padded_payload_offset, payload.begin(), |
2589 payload.begin(), static_cast<size_t>(payload.length())); | 2593 static_cast<size_t>(payload.length())); |
2590 } | 2594 } |
2591 | 2595 |
2592 | 2596 |
2593 bool SerializedCodeData::IsSane(String* source) const { | 2597 bool SerializedCodeData::IsSane(String* source) const { |
2594 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && | 2598 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && |
2595 GetHeaderValue(kSourceHashOffset) == SourceHash(source) && | 2599 GetHeaderValue(kSourceHashOffset) == SourceHash(source) && |
2596 GetHeaderValue(kCpuFeaturesOffset) == | 2600 GetHeaderValue(kCpuFeaturesOffset) == |
2597 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) && | 2601 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) && |
2598 GetHeaderValue(kFlagHashOffset) == FlagList::Hash() && | 2602 GetHeaderValue(kFlagHashOffset) == FlagList::Hash() && |
2599 Checksum(Payload()).Check(GetHeaderValue(kChecksum1Offset), | 2603 Checksum(Payload()).Check(GetHeaderValue(kChecksum1Offset), |
2600 GetHeaderValue(kChecksum2Offset)); | 2604 GetHeaderValue(kChecksum2Offset)); |
2601 } | 2605 } |
2602 | 2606 |
2603 | 2607 |
2604 // Return ScriptData object and relinquish ownership over it to the caller. | 2608 // Return ScriptData object and relinquish ownership over it to the caller. |
2605 ScriptData* SerializedCodeData::GetScriptData() { | 2609 ScriptData* SerializedCodeData::GetScriptData() { |
2606 DCHECK(owns_data_); | 2610 DCHECK(owns_data_); |
2607 ScriptData* result = new ScriptData(data_, size_); | 2611 ScriptData* result = new ScriptData(data_, size_); |
2608 result->AcquireDataOwnership(); | 2612 result->AcquireDataOwnership(); |
2609 owns_data_ = false; | 2613 owns_data_ = false; |
2610 data_ = NULL; | 2614 data_ = NULL; |
2611 return result; | 2615 return result; |
2612 } | 2616 } |
2613 | 2617 |
2614 | 2618 |
2615 Vector<const SerializedData::Reservation> SerializedCodeData::Reservations() | 2619 Vector<const SerializedData::Reservation> SerializedCodeData::Reservations() |
2616 const { | 2620 const { |
2617 return Vector<const Reservation>( | 2621 return Vector<const Reservation>( |
2618 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), | 2622 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), |
2619 GetHeaderValue(kReservationsOffset)); | 2623 GetHeaderValue(kNumReservationsOffset)); |
2620 } | 2624 } |
2621 | 2625 |
2622 | 2626 |
2623 Vector<const byte> SerializedCodeData::Payload() const { | 2627 Vector<const byte> SerializedCodeData::Payload() const { |
2624 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; | 2628 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
2625 int code_stubs_size = GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size; | 2629 int code_stubs_size = GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size; |
2626 const byte* payload = | 2630 int payload_offset = kHeaderSize + reservations_size + code_stubs_size; |
2627 data_ + kHeaderSize + reservations_size + code_stubs_size; | 2631 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); |
| 2632 const byte* payload = data_ + padded_payload_offset; |
| 2633 DCHECK(IsAligned(reinterpret_cast<intptr_t>(payload), kPointerAlignment)); |
2628 int length = GetHeaderValue(kPayloadLengthOffset); | 2634 int length = GetHeaderValue(kPayloadLengthOffset); |
2629 DCHECK_EQ(data_ + size_, payload + length); | 2635 DCHECK_EQ(data_ + size_, payload + length); |
2630 return Vector<const byte>(payload, length); | 2636 return Vector<const byte>(payload, length); |
2631 } | 2637 } |
2632 | 2638 |
2633 | 2639 |
2634 int SerializedCodeData::NumInternalizedStrings() const { | 2640 int SerializedCodeData::NumInternalizedStrings() const { |
2635 return GetHeaderValue(kNumInternalizedStringsOffset); | 2641 return GetHeaderValue(kNumInternalizedStringsOffset); |
2636 } | 2642 } |
2637 | 2643 |
2638 Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const { | 2644 Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const { |
2639 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; | 2645 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
2640 const byte* start = data_ + kHeaderSize + reservations_size; | 2646 const byte* start = data_ + kHeaderSize + reservations_size; |
2641 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start), | 2647 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start), |
2642 GetHeaderValue(kNumCodeStubKeysOffset)); | 2648 GetHeaderValue(kNumCodeStubKeysOffset)); |
2643 } | 2649 } |
2644 } } // namespace v8::internal | 2650 } } // namespace v8::internal |
OLD | NEW |