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

Side by Side Diff: src/serialize.cc

Issue 18583: Change type of snapshot from char array to byte array to avoid portability pr... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/serialize.h ('k') | src/snapshot.h » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 // Implementation of Serializer 679 // Implementation of Serializer
680 680
681 681
682 // Helper class to write the bytes of the serialized heap. 682 // Helper class to write the bytes of the serialized heap.
683 683
684 class SnapshotWriter { 684 class SnapshotWriter {
685 public: 685 public:
686 SnapshotWriter() { 686 SnapshotWriter() {
687 len_ = 0; 687 len_ = 0;
688 max_ = 8 << 10; // 8K initial size 688 max_ = 8 << 10; // 8K initial size
689 str_ = NewArray<char>(max_); 689 str_ = NewArray<byte>(max_);
690 } 690 }
691 691
692 ~SnapshotWriter() { 692 ~SnapshotWriter() {
693 DeleteArray(str_); 693 DeleteArray(str_);
694 } 694 }
695 695
696 void GetString(char** str, int* len) { 696 void GetBytes(byte** str, int* len) {
697 *str = NewArray<char>(len_); 697 *str = NewArray<byte>(len_);
698 memcpy(*str, str_, len_); 698 memcpy(*str, str_, len_);
699 *len = len_; 699 *len = len_;
700 } 700 }
701 701
702 void Reserve(int bytes, int pos); 702 void Reserve(int bytes, int pos);
703 703
704 void PutC(char c) { 704 void PutC(char c) {
705 InsertC(c, len_); 705 InsertC(c, len_);
706 } 706 }
707 707
(...skipping 27 matching lines...) Expand all
735 return pos + size; 735 return pos + size;
736 } 736 }
737 737
738 int InsertString(const char* s, int pos); 738 int InsertString(const char* s, int pos);
739 739
740 int length() { return len_; } 740 int length() { return len_; }
741 741
742 Address position() { return reinterpret_cast<Address>(&str_[len_]); } 742 Address position() { return reinterpret_cast<Address>(&str_[len_]); }
743 743
744 private: 744 private:
745 char* str_; // the snapshot 745 byte* str_; // the snapshot
746 int len_; // the current length of str_ 746 int len_; // the current length of str_
747 int max_; // the allocated size of str_ 747 int max_; // the allocated size of str_
748 }; 748 };
749 749
750 750
751 void SnapshotWriter::Reserve(int bytes, int pos) { 751 void SnapshotWriter::Reserve(int bytes, int pos) {
752 CHECK(0 <= pos && pos <= len_); 752 CHECK(0 <= pos && pos <= len_);
753 while (len_ + bytes >= max_) { 753 while (len_ + bytes >= max_) {
754 max_ *= 2; 754 max_ *= 2;
755 char* old = str_; 755 byte* old = str_;
756 str_ = NewArray<char>(max_); 756 str_ = NewArray<byte>(max_);
757 memcpy(str_, old, len_); 757 memcpy(str_, old, len_);
758 DeleteArray(old); 758 DeleteArray(old);
759 } 759 }
760 if (pos < len_) { 760 if (pos < len_) {
761 char* old = str_; 761 byte* old = str_;
762 str_ = NewArray<char>(max_); 762 str_ = NewArray<byte>(max_);
763 memcpy(str_, old, pos); 763 memcpy(str_, old, pos);
764 memcpy(str_ + pos + bytes, old + pos, len_ - pos); 764 memcpy(str_ + pos + bytes, old + pos, len_ - pos);
765 DeleteArray(old); 765 DeleteArray(old);
766 } 766 }
767 } 767 }
768 768
769 int SnapshotWriter::InsertString(const char* s, int pos) { 769 int SnapshotWriter::InsertString(const char* s, int pos) {
770 int size = strlen(s); 770 int size = strlen(s);
771 pos = InsertC('[', pos); 771 pos = InsertC('[', pos);
772 pos = InsertInt(size, pos); 772 pos = InsertInt(size, pos);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 InitializeAllocators(); 922 InitializeAllocators();
923 reference_encoder_ = new ExternalReferenceEncoder(); 923 reference_encoder_ = new ExternalReferenceEncoder();
924 PutHeader(); 924 PutHeader();
925 Heap::IterateRoots(this); 925 Heap::IterateRoots(this);
926 PutLog(); 926 PutLog();
927 PutContextStack(); 927 PutContextStack();
928 disable(); 928 disable();
929 } 929 }
930 930
931 931
932 void Serializer::Finalize(char** str, int* len) { 932 void Serializer::Finalize(byte** str, int* len) {
933 writer_->GetString(str, len); 933 writer_->GetBytes(str, len);
934 } 934 }
935 935
936 936
937 // Serialize objects by writing them into the stream. 937 // Serialize objects by writing them into the stream.
938 938
939 void Serializer::VisitPointers(Object** start, Object** end) { 939 void Serializer::VisitPointers(Object** start, Object** end) {
940 bool root = root_; 940 bool root = root_;
941 root_ = false; 941 root_ = false;
942 for (Object** p = start; p < end; ++p) { 942 for (Object** p = start; p < end; ++p) {
943 bool serialized; 943 bool serialized;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 } 1173 }
1174 1174
1175 1175
1176 //------------------------------------------------------------------------------ 1176 //------------------------------------------------------------------------------
1177 // Implementation of Deserializer 1177 // Implementation of Deserializer
1178 1178
1179 1179
1180 static const int kInitArraySize = 32; 1180 static const int kInitArraySize = 32;
1181 1181
1182 1182
1183 Deserializer::Deserializer(const char* str, int len) 1183 Deserializer::Deserializer(const byte* str, int len)
1184 : reader_(str, len), 1184 : reader_(str, len),
1185 map_pages_(kInitArraySize), 1185 map_pages_(kInitArraySize),
1186 old_pointer_pages_(kInitArraySize), 1186 old_pointer_pages_(kInitArraySize),
1187 old_data_pages_(kInitArraySize), 1187 old_data_pages_(kInitArraySize),
1188 code_pages_(kInitArraySize), 1188 code_pages_(kInitArraySize),
1189 large_objects_(kInitArraySize), 1189 large_objects_(kInitArraySize),
1190 global_handles_(4) { 1190 global_handles_(4) {
1191 root_ = true; 1191 root_ = true;
1192 roots_ = 0; 1192 roots_ = 0;
1193 objects_ = 0; 1193 objects_ = 0;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 ASSERT(index < large_objects_.length()); 1519 ASSERT(index < large_objects_.length());
1520 } 1520 }
1521 return large_objects_[index]; // s.page_offset() is ignored. 1521 return large_objects_[index]; // s.page_offset() is ignored.
1522 } 1522 }
1523 UNREACHABLE(); 1523 UNREACHABLE();
1524 return NULL; 1524 return NULL;
1525 } 1525 }
1526 1526
1527 1527
1528 } } // namespace v8::internal 1528 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | src/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698