Correctly pointer-align code cache payload.

R=jochen@chromium.org

Review URL: https://codereview.chromium.org/912763002

Cr-Commit-Position: refs/heads/master@{#26541}
This commit is contained in:
yangguo 2015-02-10 03:19:57 -08:00 committed by Commit bot
parent 1db760de7d
commit bee9a0accb
2 changed files with 44 additions and 30 deletions

View File

@ -2475,7 +2475,7 @@ SnapshotData::SnapshotData(const SnapshotByteSink& sink,
// Set header values.
SetHeaderValue(kCheckSumOffset, Version::Hash());
SetHeaderValue(kReservationsOffset, reservations.length());
SetHeaderValue(kNumReservationsOffset, reservations.length());
SetHeaderValue(kPayloadLengthOffset, payload.length());
// Copy reservation chunk sizes.
@ -2496,12 +2496,12 @@ bool SnapshotData::IsSane() {
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);
@ -2556,7 +2556,9 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload,
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);
@ -2568,7 +2570,7 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload,
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());
@ -2584,9 +2586,11 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload,
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()));
}
@ -2616,15 +2620,17 @@ Vector<const SerializedData::Reservation> SerializedCodeData::Reservations()
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);
@ -2636,7 +2642,7 @@ int SerializedCodeData::NumInternalizedStrings() const {
}
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));

View File

@ -501,12 +501,13 @@ class SerializedData {
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;
}
@ -912,14 +913,16 @@ class SnapshotData : public SerializedData {
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;
};
@ -957,7 +960,7 @@ class SerializedCodeData : public SerializedData {
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
@ -966,18 +969,23 @@ class SerializedCodeData : public SerializedData {
// [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