// Set header values.
SetHeaderValue(kCheckSumOffset, Version::Hash());
- SetHeaderValue(kReservationsOffset, reservations.length());
+ SetHeaderValue(kNumReservationsOffset, reservations.length());
SetHeaderValue(kPayloadLengthOffset, payload.length());
// Copy reservation chunk sizes.
Vector<const SerializedData::Reservation> SnapshotData::Reservations() const {
return Vector<const Reservation>(
reinterpret_cast<const Reservation*>(data_ + kHeaderSize),
- GetHeaderValue(kReservationsOffset));
+ GetHeaderValue(kNumReservationsOffset));
}
Vector<const byte> SnapshotData::Payload() const {
- int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
+ int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size;
const byte* payload = data_ + kHeaderSize + reservations_size;
int length = GetHeaderValue(kPayloadLengthOffset);
DCHECK_EQ(data_ + size_, payload + length);
int reservation_size = reservations.length() * kInt32Size;
int num_stub_keys = stub_keys->length();
int stub_keys_size = stub_keys->length() * kInt32Size;
- int size = kHeaderSize + reservation_size + stub_keys_size + payload.length();
+ int payload_offset = kHeaderSize + reservation_size + stub_keys_size;
+ int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset);
+ int size = padded_payload_offset + payload.length();
// Allocate backing store and create result data.
AllocateData(size);
static_cast<uint32_t>(CpuFeatures::SupportedFeatures()));
SetHeaderValue(kFlagHashOffset, FlagList::Hash());
SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings());
- SetHeaderValue(kReservationsOffset, reservations.length());
+ SetHeaderValue(kNumReservationsOffset, reservations.length());
SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
SetHeaderValue(kPayloadLengthOffset, payload.length());
CopyBytes(data_ + kHeaderSize + reservation_size,
reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size);
+ memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset);
+
// Copy serialized data.
- CopyBytes(data_ + kHeaderSize + reservation_size + stub_keys_size,
- payload.begin(), static_cast<size_t>(payload.length()));
+ CopyBytes(data_ + padded_payload_offset, payload.begin(),
+ static_cast<size_t>(payload.length()));
}
const {
return Vector<const Reservation>(
reinterpret_cast<const Reservation*>(data_ + kHeaderSize),
- GetHeaderValue(kReservationsOffset));
+ GetHeaderValue(kNumReservationsOffset));
}
Vector<const byte> SerializedCodeData::Payload() const {
- int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
+ int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size;
int code_stubs_size = GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size;
- const byte* payload =
- data_ + kHeaderSize + reservations_size + code_stubs_size;
+ int payload_offset = kHeaderSize + reservations_size + code_stubs_size;
+ int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset);
+ const byte* payload = data_ + padded_payload_offset;
+ DCHECK(IsAligned(reinterpret_cast<intptr_t>(payload), kPointerAlignment));
int length = GetHeaderValue(kPayloadLengthOffset);
DCHECK_EQ(data_ + size_, payload + length);
return Vector<const byte>(payload, length);
}
Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const {
- int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
+ int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size;
const byte* start = data_ + kHeaderSize + reservations_size;
return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start),
GetHeaderValue(kNumCodeStubKeysOffset));
protected:
void SetHeaderValue(int offset, uint32_t value) {
- memcpy(reinterpret_cast<uint32_t*>(data_) + offset, &value, sizeof(value));
+ uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset);
+ memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value));
}
uint32_t GetHeaderValue(int offset) const {
uint32_t value;
- memcpy(&value, reinterpret_cast<int*>(data_) + offset, sizeof(value));
+ memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value));
return value;
}
private:
bool IsSane();
- // The data header consists of int-sized entries:
+ // The data header consists of uint32_t-sized entries:
// [0] version hash
// [1] number of reservation size entries
// [2] payload length
+ // ... reservations
+ // ... serialized payload
static const int kCheckSumOffset = 0;
- static const int kReservationsOffset = 1;
- static const int kPayloadLengthOffset = 2;
- static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize;
+ static const int kNumReservationsOffset = kCheckSumOffset + kInt32Size;
+ static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size;
+ static const int kHeaderSize = kPayloadLengthOffset + kInt32Size;
};
uint32_t SourceHash(String* source) const { return source->length(); }
- // The data header consists of int-sized entries:
+ // The data header consists of uint32_t-sized entries:
// [0] version hash
// [1] source hash
// [2] cpu features
// [5] number of code stub keys
// [6] number of reservation size entries
// [7] payload length
+ // [8] payload checksum part 1
+ // [9] payload checksum part 2
+ // ... reservations
+ // ... code stub keys
+ // ... serialized payload
static const int kVersionHashOffset = 0;
- static const int kSourceHashOffset = 1;
- static const int kCpuFeaturesOffset = 2;
- static const int kFlagHashOffset = 3;
- static const int kNumInternalizedStringsOffset = 4;
- static const int kReservationsOffset = 5;
- static const int kNumCodeStubKeysOffset = 6;
- static const int kPayloadLengthOffset = 7;
- static const int kChecksum1Offset = 8;
- static const int kChecksum2Offset = 9;
- static const int kHeaderSize =
- POINTER_SIZE_ALIGN((kChecksum2Offset + 1) * kIntSize);
+ static const int kSourceHashOffset = kVersionHashOffset + kInt32Size;
+ static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size;
+ static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size;
+ static const int kNumInternalizedStringsOffset = kFlagHashOffset + kInt32Size;
+ static const int kNumReservationsOffset =
+ kNumInternalizedStringsOffset + kInt32Size;
+ static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size;
+ static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
+ static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
+ static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
+ static const int kHeaderSize = kChecksum2Offset + kInt32Size;
};
} } // namespace v8::internal