Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/serialize.h

Issue 912763002: Correctly pointer-align code cache payload. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: small fix Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/serialize.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef V8_SERIALIZE_H_ 5 #ifndef V8_SERIALIZE_H_
6 #define V8_SERIALIZE_H_ 6 #define V8_SERIALIZE_H_
7 7
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/heap-profiler.h" 10 #include "src/heap-profiler.h"
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 494
495 ~SerializedData() { 495 ~SerializedData() {
496 if (owns_data_) DeleteArray<byte>(data_); 496 if (owns_data_) DeleteArray<byte>(data_);
497 } 497 }
498 498
499 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {}; 499 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};
500 class IsLastChunkBits : public BitField<bool, 31, 1> {}; 500 class IsLastChunkBits : public BitField<bool, 31, 1> {};
501 501
502 protected: 502 protected:
503 void SetHeaderValue(int offset, uint32_t value) { 503 void SetHeaderValue(int offset, uint32_t value) {
504 memcpy(reinterpret_cast<uint32_t*>(data_) + offset, &value, sizeof(value)); 504 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset);
505 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value));
505 } 506 }
506 507
507 uint32_t GetHeaderValue(int offset) const { 508 uint32_t GetHeaderValue(int offset) const {
508 uint32_t value; 509 uint32_t value;
509 memcpy(&value, reinterpret_cast<int*>(data_) + offset, sizeof(value)); 510 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value));
510 return value; 511 return value;
511 } 512 }
512 513
513 void AllocateData(int size); 514 void AllocateData(int size);
514 515
515 byte* data_; 516 byte* data_;
516 int size_; 517 int size_;
517 bool owns_data_; 518 bool owns_data_;
518 }; 519 };
519 520
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 906
906 Vector<const Reservation> Reservations() const; 907 Vector<const Reservation> Reservations() const;
907 Vector<const byte> Payload() const; 908 Vector<const byte> Payload() const;
908 909
909 Vector<const byte> RawData() const { 910 Vector<const byte> RawData() const {
910 return Vector<const byte>(data_, size_); 911 return Vector<const byte>(data_, size_);
911 } 912 }
912 913
913 private: 914 private:
914 bool IsSane(); 915 bool IsSane();
915 // The data header consists of int-sized entries: 916 // The data header consists of uint32_t-sized entries:
916 // [0] version hash 917 // [0] version hash
917 // [1] number of reservation size entries 918 // [1] number of reservation size entries
918 // [2] payload length 919 // [2] payload length
920 // ... reservations
921 // ... serialized payload
919 static const int kCheckSumOffset = 0; 922 static const int kCheckSumOffset = 0;
920 static const int kReservationsOffset = 1; 923 static const int kNumReservationsOffset = kCheckSumOffset + kInt32Size;
921 static const int kPayloadLengthOffset = 2; 924 static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size;
922 static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize; 925 static const int kHeaderSize = kPayloadLengthOffset + kInt32Size;
923 }; 926 };
924 927
925 928
926 // Wrapper around ScriptData to provide code-serializer-specific functionality. 929 // Wrapper around ScriptData to provide code-serializer-specific functionality.
927 class SerializedCodeData : public SerializedData { 930 class SerializedCodeData : public SerializedData {
928 public: 931 public:
929 // Used when consuming. 932 // Used when consuming.
930 static SerializedCodeData* FromCachedData(ScriptData* cached_data, 933 static SerializedCodeData* FromCachedData(ScriptData* cached_data,
931 String* source) { 934 String* source) {
932 DisallowHeapAllocation no_gc; 935 DisallowHeapAllocation no_gc;
(...skipping 17 matching lines...) Expand all
950 Vector<const uint32_t> CodeStubKeys() const; 953 Vector<const uint32_t> CodeStubKeys() const;
951 954
952 private: 955 private:
953 explicit SerializedCodeData(ScriptData* data) 956 explicit SerializedCodeData(ScriptData* data)
954 : SerializedData(const_cast<byte*>(data->data()), data->length()) {} 957 : SerializedData(const_cast<byte*>(data->data()), data->length()) {}
955 958
956 bool IsSane(String* source) const; 959 bool IsSane(String* source) const;
957 960
958 uint32_t SourceHash(String* source) const { return source->length(); } 961 uint32_t SourceHash(String* source) const { return source->length(); }
959 962
960 // The data header consists of int-sized entries: 963 // The data header consists of uint32_t-sized entries:
961 // [0] version hash 964 // [0] version hash
962 // [1] source hash 965 // [1] source hash
963 // [2] cpu features 966 // [2] cpu features
964 // [3] flag hash 967 // [3] flag hash
965 // [4] number of internalized strings 968 // [4] number of internalized strings
966 // [5] number of code stub keys 969 // [5] number of code stub keys
967 // [6] number of reservation size entries 970 // [6] number of reservation size entries
968 // [7] payload length 971 // [7] payload length
972 // [8] payload checksum part 1
973 // [9] payload checksum part 2
974 // ... reservations
975 // ... code stub keys
976 // ... serialized payload
969 static const int kVersionHashOffset = 0; 977 static const int kVersionHashOffset = 0;
970 static const int kSourceHashOffset = 1; 978 static const int kSourceHashOffset = kVersionHashOffset + kInt32Size;
971 static const int kCpuFeaturesOffset = 2; 979 static const int kCpuFeaturesOffset = kSourceHashOffset + kInt32Size;
972 static const int kFlagHashOffset = 3; 980 static const int kFlagHashOffset = kCpuFeaturesOffset + kInt32Size;
973 static const int kNumInternalizedStringsOffset = 4; 981 static const int kNumInternalizedStringsOffset = kFlagHashOffset + kInt32Size;
974 static const int kReservationsOffset = 5; 982 static const int kNumReservationsOffset =
975 static const int kNumCodeStubKeysOffset = 6; 983 kNumInternalizedStringsOffset + kInt32Size;
976 static const int kPayloadLengthOffset = 7; 984 static const int kNumCodeStubKeysOffset = kNumReservationsOffset + kInt32Size;
977 static const int kChecksum1Offset = 8; 985 static const int kPayloadLengthOffset = kNumCodeStubKeysOffset + kInt32Size;
978 static const int kChecksum2Offset = 9; 986 static const int kChecksum1Offset = kPayloadLengthOffset + kInt32Size;
979 static const int kHeaderSize = 987 static const int kChecksum2Offset = kChecksum1Offset + kInt32Size;
980 POINTER_SIZE_ALIGN((kChecksum2Offset + 1) * kIntSize); 988 static const int kHeaderSize = kChecksum2Offset + kInt32Size;
981 }; 989 };
982 } } // namespace v8::internal 990 } } // namespace v8::internal
983 991
984 #endif // V8_SERIALIZE_H_ 992 #endif // V8_SERIALIZE_H_
OLDNEW
« no previous file with comments | « no previous file | src/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698