| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 curent 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { | 807 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { |
| 808 Address target = rinfo->target_address(); | 808 Address target = rinfo->target_address(); |
| 809 uint32_t encoding = reference_encoder_->Encode(target); | 809 uint32_t encoding = reference_encoder_->Encode(target); |
| 810 CHECK(target == NULL ? encoding == 0 : encoding != 0); | 810 CHECK(target == NULL ? encoding == 0 : encoding != 0); |
| 811 offsets_.Add(rinfo->target_address_address() - obj_address_); | 811 offsets_.Add(rinfo->target_address_address() - obj_address_); |
| 812 addresses_.Add(reinterpret_cast<Address>(encoding)); | 812 addresses_.Add(reinterpret_cast<Address>(encoding)); |
| 813 } | 813 } |
| 814 | 814 |
| 815 void Update(Address start_address) { | 815 void Update(Address start_address) { |
| 816 for (int i = 0; i < offsets_.length(); i++) { | 816 for (int i = 0; i < offsets_.length(); i++) { |
| 817 Address* p = reinterpret_cast<Address*>(start_address + offsets_[i]); | 817 memcpy(start_address + offsets_[i], &addresses_[i], sizeof(Address)); |
| 818 *p = addresses_[i]; | |
| 819 } | 818 } |
| 820 } | 819 } |
| 821 | 820 |
| 822 private: | 821 private: |
| 823 Address obj_address_; | 822 Address obj_address_; |
| 824 Serializer* serializer_; | 823 Serializer* serializer_; |
| 825 ExternalReferenceEncoder* reference_encoder_; | 824 ExternalReferenceEncoder* reference_encoder_; |
| 826 List<int> offsets_; | 825 List<int> offsets_; |
| 827 List<Address> addresses_; | 826 List<Address> addresses_; |
| 828 }; | 827 }; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 InitializeAllocators(); | 921 InitializeAllocators(); |
| 923 reference_encoder_ = new ExternalReferenceEncoder(); | 922 reference_encoder_ = new ExternalReferenceEncoder(); |
| 924 PutHeader(); | 923 PutHeader(); |
| 925 Heap::IterateRoots(this); | 924 Heap::IterateRoots(this); |
| 926 PutLog(); | 925 PutLog(); |
| 927 PutContextStack(); | 926 PutContextStack(); |
| 928 disable(); | 927 disable(); |
| 929 } | 928 } |
| 930 | 929 |
| 931 | 930 |
| 932 void Serializer::Finalize(char** str, int* len) { | 931 void Serializer::Finalize(byte** str, int* len) { |
| 933 writer_->GetString(str, len); | 932 writer_->GetBytes(str, len); |
| 934 } | 933 } |
| 935 | 934 |
| 936 | 935 |
| 937 // Serialize objects by writing them into the stream. | 936 // Serialize objects by writing them into the stream. |
| 938 | 937 |
| 939 void Serializer::VisitPointers(Object** start, Object** end) { | 938 void Serializer::VisitPointers(Object** start, Object** end) { |
| 940 bool root = root_; | 939 bool root = root_; |
| 941 root_ = false; | 940 root_ = false; |
| 942 for (Object** p = start; p < end; ++p) { | 941 for (Object** p = start; p < end; ++p) { |
| 943 bool serialized; | 942 bool serialized; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 } | 1172 } |
| 1174 | 1173 |
| 1175 | 1174 |
| 1176 //------------------------------------------------------------------------------ | 1175 //------------------------------------------------------------------------------ |
| 1177 // Implementation of Deserializer | 1176 // Implementation of Deserializer |
| 1178 | 1177 |
| 1179 | 1178 |
| 1180 static const int kInitArraySize = 32; | 1179 static const int kInitArraySize = 32; |
| 1181 | 1180 |
| 1182 | 1181 |
| 1183 Deserializer::Deserializer(const char* str, int len) | 1182 Deserializer::Deserializer(const byte* str, int len) |
| 1184 : reader_(str, len), | 1183 : reader_(str, len), |
| 1185 map_pages_(kInitArraySize), | 1184 map_pages_(kInitArraySize), |
| 1186 old_pointer_pages_(kInitArraySize), | 1185 old_pointer_pages_(kInitArraySize), |
| 1187 old_data_pages_(kInitArraySize), | 1186 old_data_pages_(kInitArraySize), |
| 1188 code_pages_(kInitArraySize), | 1187 code_pages_(kInitArraySize), |
| 1189 large_objects_(kInitArraySize), | 1188 large_objects_(kInitArraySize), |
| 1190 global_handles_(4) { | 1189 global_handles_(4) { |
| 1191 root_ = true; | 1190 root_ = true; |
| 1192 roots_ = 0; | 1191 roots_ = 0; |
| 1193 objects_ = 0; | 1192 objects_ = 0; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 ASSERT(index < large_objects_.length()); | 1518 ASSERT(index < large_objects_.length()); |
| 1520 } | 1519 } |
| 1521 return large_objects_[index]; // s.page_offset() is ignored. | 1520 return large_objects_[index]; // s.page_offset() is ignored. |
| 1522 } | 1521 } |
| 1523 UNREACHABLE(); | 1522 UNREACHABLE(); |
| 1524 return NULL; | 1523 return NULL; |
| 1525 } | 1524 } |
| 1526 | 1525 |
| 1527 | 1526 |
| 1528 } } // namespace v8::internal | 1527 } } // namespace v8::internal |
| OLD | NEW |