Reviewers: jochen (slow),

Description:
Correctly pointer-align code cache payload.

[email protected]

Please review this at https://codereview.chromium.org/912763002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+22, -10 lines):
  M src/serialize.h
  M src/serialize.cc


Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index e2ff9f42f3d79a52c0301f43c164f4bbd91fa1a4..b8bf4205acdec8a6757d7c6a37d3232222d53648 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -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 = kHeaderSize + padded_payload_offset + payload.length();

   // Allocate backing store and create result data.
   AllocateData(size);
@@ -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()));
 }


@@ -2623,8 +2627,10 @@ Vector<const SerializedData::Reservation> SerializedCodeData::Reservations()
 Vector<const byte> SerializedCodeData::Payload() const {
   int reservations_size = GetHeaderValue(kReservationsOffset) * 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);
Index: src/serialize.h
diff --git a/src/serialize.h b/src/serialize.h
index 264bd46f460015a392047afaeb9a478bcf0054a7..30eb364892ce0728e06245f69aa276108b9b7082 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -912,14 +912,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 kHeaderSize = (kPayloadLengthOffset + 1) * sizeof(uint32_t);
 };


@@ -957,7 +959,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,6 +968,11 @@ 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;
@@ -976,8 +983,7 @@ class SerializedCodeData : public SerializedData {
   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 kHeaderSize = (kChecksum2Offset + 1) * sizeof(uint32_t);
 };
 } }  // namespace v8::internal



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to