| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/bigint_operations.h" | 5 #include "vm/bigint_operations.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
| 8 #include "vm/snapshot.h" | 8 #include "vm/snapshot.h" |
| 9 #include "vm/visitor.h" | 9 #include "vm/visitor.h" |
| 10 | 10 |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 } | 981 } |
| 982 | 982 |
| 983 | 983 |
| 984 void RawString::WriteTo(SnapshotWriter* writer, | 984 void RawString::WriteTo(SnapshotWriter* writer, |
| 985 intptr_t object_id, | 985 intptr_t object_id, |
| 986 bool serialize_classes) { | 986 bool serialize_classes) { |
| 987 UNREACHABLE(); // String is an abstract class. | 987 UNREACHABLE(); // String is an abstract class. |
| 988 } | 988 } |
| 989 | 989 |
| 990 | 990 |
| 991 template<typename HandleType, typename CharacterType> |
| 992 RawString* String::ReadFromImpl(SnapshotReader* reader, |
| 993 intptr_t object_id, |
| 994 bool classes_serialized) { |
| 995 ASSERT(reader != NULL); |
| 996 // Read the length so that we can determine instance size to allocate. |
| 997 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 998 intptr_t len = Smi::Value(smi_len); |
| 999 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); |
| 1000 |
| 1001 // Set up the string object. |
| 1002 HandleType& str_obj = HandleType::ZoneHandle( |
| 1003 HandleType::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); |
| 1004 for (intptr_t i = 0; i < len; i++) { |
| 1005 *str_obj.CharAddr(i) = reader->Read<CharacterType>(); |
| 1006 } |
| 1007 reader->AddBackwardReference(object_id, &str_obj); |
| 1008 str_obj.SetHash(Smi::Value(smi_hash)); |
| 1009 return str_obj.raw(); |
| 1010 } |
| 1011 |
| 1012 |
| 991 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1013 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 992 intptr_t object_id, | 1014 intptr_t object_id, |
| 993 bool classes_serialized) { | 1015 bool classes_serialized) { |
| 994 ASSERT(reader != NULL); | 1016 return static_cast<RawOneByteString*>( |
| 995 // Read the length so that we can determine instance size to allocate. | 1017 ReadFromImpl<OneByteString, uint8_t>(reader, |
| 996 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1018 object_id, |
| 997 intptr_t len = Smi::Value(smi_len); | 1019 classes_serialized)); |
| 998 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | 1020 } |
| 999 | 1021 |
| 1000 // Set up the one byte string object. | 1022 |
| 1001 OneByteString& str_obj = OneByteString::ZoneHandle( | 1023 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1002 OneByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | 1024 intptr_t object_id, |
| 1025 bool classes_serialized) { |
| 1026 return static_cast<RawTwoByteString*>( |
| 1027 ReadFromImpl<TwoByteString, uint16_t>(reader, |
| 1028 object_id, |
| 1029 classes_serialized)); |
| 1030 } |
| 1031 |
| 1032 |
| 1033 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
| 1034 intptr_t object_id, |
| 1035 bool classes_serialized) { |
| 1036 return static_cast<RawFourByteString*>( |
| 1037 ReadFromImpl<FourByteString, uint32_t>(reader, |
| 1038 object_id, |
| 1039 classes_serialized)); |
| 1040 } |
| 1041 |
| 1042 |
| 1043 template<typename T> |
| 1044 static void StringWriteTo(SnapshotWriter* writer, |
| 1045 intptr_t object_id, |
| 1046 intptr_t class_id, |
| 1047 bool serialize_classes, |
| 1048 RawSmi* length, |
| 1049 RawSmi* hash, |
| 1050 T* data) { |
| 1051 ASSERT(writer != NULL); |
| 1052 intptr_t len = Smi::Value(length); |
| 1053 |
| 1054 // Write out the serialization header value for this object. |
| 1055 writer->WriteObjectHeader(kInlined, object_id); |
| 1056 |
| 1057 // Write out the class information. |
| 1058 writer->WriteObjectHeader(kObjectId, class_id); |
| 1059 |
| 1060 // Write out the length field. |
| 1061 writer->Write<RawObject*>(length); |
| 1062 |
| 1063 // Write out the hash field. |
| 1064 writer->Write<RawObject*>(hash); |
| 1065 |
| 1066 // Write out the string. |
| 1003 for (intptr_t i = 0; i < len; i++) { | 1067 for (intptr_t i = 0; i < len; i++) { |
| 1004 *str_obj.CharAddr(i) = reader->Read<uint8_t>(); | 1068 writer->Write(data[i]); |
| 1005 } | 1069 } |
| 1006 | |
| 1007 reader->AddBackwardReference(object_id, &str_obj); | |
| 1008 RawOneByteString* raw_str = str_obj.raw(); | |
| 1009 raw_str->ptr()->hash_ = smi_hash; | |
| 1010 return str_obj.raw(); | |
| 1011 } | 1070 } |
| 1012 | 1071 |
| 1013 | 1072 |
| 1014 void RawOneByteString::WriteTo(SnapshotWriter* writer, | 1073 void RawOneByteString::WriteTo(SnapshotWriter* writer, |
| 1015 intptr_t object_id, | 1074 intptr_t object_id, |
| 1016 bool serialize_classes) { | 1075 bool serialize_classes) { |
| 1017 ASSERT(writer != NULL); | 1076 StringWriteTo(writer, |
| 1018 intptr_t len = Smi::Value(ptr()->length_); | 1077 object_id, |
| 1019 | 1078 ObjectStore::kOneByteStringClass, |
| 1020 // Write out the serialization header value for this object. | 1079 serialize_classes, |
| 1021 writer->WriteObjectHeader(kInlined, object_id); | 1080 ptr()->length_, |
| 1022 | 1081 ptr()->hash_, |
| 1023 // Write out the class information. | 1082 ptr()->data_); |
| 1024 writer->WriteObjectHeader(kObjectId, ObjectStore::kOneByteStringClass); | |
| 1025 | |
| 1026 // Write out the length field. | |
| 1027 writer->Write<RawObject*>(ptr()->length_); | |
| 1028 | |
| 1029 // Write out the hash field. | |
| 1030 writer->Write<RawObject*>(ptr()->hash_); | |
| 1031 | |
| 1032 // Write out the string. | |
| 1033 for (intptr_t i = 0; i < len; i++) { | |
| 1034 writer->Write<uint8_t>(ptr()->data_[i]); | |
| 1035 } | |
| 1036 } | |
| 1037 | |
| 1038 | |
| 1039 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | |
| 1040 intptr_t object_id, | |
| 1041 bool classes_serialized) { | |
| 1042 ASSERT(reader != NULL); | |
| 1043 // Read the length so that we can determine instance size to allocate. | |
| 1044 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | |
| 1045 intptr_t len = Smi::Value(smi_len); | |
| 1046 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | |
| 1047 | |
| 1048 // Set up the two byte string object. | |
| 1049 TwoByteString& str_obj = TwoByteString::ZoneHandle( | |
| 1050 TwoByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | |
| 1051 for (intptr_t i = 0; i < len; i++) { | |
| 1052 *str_obj.CharAddr(i) = reader->Read<uint16_t>(); | |
| 1053 } | |
| 1054 | |
| 1055 reader->AddBackwardReference(object_id, &str_obj); | |
| 1056 RawTwoByteString* raw_str = str_obj.raw(); | |
| 1057 raw_str->ptr()->hash_ = smi_hash; | |
| 1058 return str_obj.raw(); | |
| 1059 } | 1083 } |
| 1060 | 1084 |
| 1061 | 1085 |
| 1062 void RawTwoByteString::WriteTo(SnapshotWriter* writer, | 1086 void RawTwoByteString::WriteTo(SnapshotWriter* writer, |
| 1063 intptr_t object_id, | 1087 intptr_t object_id, |
| 1064 bool serialize_classes) { | 1088 bool serialize_classes) { |
| 1065 ASSERT(writer != NULL); | 1089 StringWriteTo(writer, |
| 1066 intptr_t len = Smi::Value(ptr()->length_); | 1090 object_id, |
| 1067 | 1091 ObjectStore::kTwoByteStringClass, |
| 1068 // Write out the serialization header value for this object. | 1092 serialize_classes, |
| 1069 writer->WriteObjectHeader(kInlined, object_id); | 1093 ptr()->length_, |
| 1070 | 1094 ptr()->hash_, |
| 1071 // Write out the class information. | 1095 ptr()->data_); |
| 1072 writer->WriteObjectHeader(kObjectId, ObjectStore::kTwoByteStringClass); | |
| 1073 | |
| 1074 // Write out the length field. | |
| 1075 writer->Write<RawObject*>(ptr()->length_); | |
| 1076 | |
| 1077 // Write out the hash field. | |
| 1078 writer->Write<RawObject*>(ptr()->hash_); | |
| 1079 | |
| 1080 // Write out the string. | |
| 1081 for (intptr_t i = 0; i < len; i++) { | |
| 1082 writer->Write<uint16_t>(ptr()->data_[i]); | |
| 1083 } | |
| 1084 } | |
| 1085 | |
| 1086 | |
| 1087 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | |
| 1088 intptr_t object_id, | |
| 1089 bool classes_serialized) { | |
| 1090 ASSERT(reader != NULL); | |
| 1091 // Read the length so that we can determine instance size to allocate. | |
| 1092 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | |
| 1093 intptr_t len = Smi::Value(smi_len); | |
| 1094 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | |
| 1095 | |
| 1096 // Set up the four byte string object. | |
| 1097 FourByteString& str_obj = FourByteString::ZoneHandle( | |
| 1098 FourByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | |
| 1099 for (intptr_t i = 0; i < len; i++) { | |
| 1100 *str_obj.CharAddr(i) = reader->Read<uint32_t>(); | |
| 1101 } | |
| 1102 | |
| 1103 reader->AddBackwardReference(object_id, &str_obj); | |
| 1104 RawFourByteString* raw_str = str_obj.raw(); | |
| 1105 raw_str->ptr()->hash_ = smi_hash; | |
| 1106 return str_obj.raw(); | |
| 1107 } | 1096 } |
| 1108 | 1097 |
| 1109 | 1098 |
| 1110 void RawFourByteString::WriteTo(SnapshotWriter* writer, | 1099 void RawFourByteString::WriteTo(SnapshotWriter* writer, |
| 1111 intptr_t object_id, | 1100 intptr_t object_id, |
| 1112 bool serialize_classes) { | 1101 bool serialize_classes) { |
| 1113 ASSERT(writer != NULL); | 1102 StringWriteTo(writer, |
| 1114 intptr_t len = Smi::Value(ptr()->length_); | 1103 object_id, |
| 1115 | 1104 ObjectStore::kFourByteStringClass, |
| 1116 // Write out the serialization header value for this object. | 1105 serialize_classes, |
| 1117 writer->WriteObjectHeader(kInlined, object_id); | 1106 ptr()->length_, |
| 1118 | 1107 ptr()->hash_, |
| 1119 // Write out the class information. | 1108 ptr()->data_); |
| 1120 writer->WriteObjectHeader(kObjectId, ObjectStore::kFourByteStringClass); | |
| 1121 | |
| 1122 // Write out the length field. | |
| 1123 writer->Write<RawObject*>(ptr()->length_); | |
| 1124 | |
| 1125 // Write out the hash field. | |
| 1126 writer->Write<RawObject*>(ptr()->hash_); | |
| 1127 | |
| 1128 // Write out the string. | |
| 1129 for (intptr_t i = 0; i < len; i++) { | |
| 1130 writer->Write<uint32_t>(ptr()->data_[i]); | |
| 1131 } | |
| 1132 } | 1109 } |
| 1133 | 1110 |
| 1134 | 1111 |
| 1135 RawBool* Bool::ReadFrom(SnapshotReader* reader, | 1112 RawBool* Bool::ReadFrom(SnapshotReader* reader, |
| 1136 intptr_t object_id, | 1113 intptr_t object_id, |
| 1137 bool classes_serialized) { | 1114 bool classes_serialized) { |
| 1138 UNREACHABLE(); | 1115 UNREACHABLE(); |
| 1139 return Bool::null(); | 1116 return Bool::null(); |
| 1140 } | 1117 } |
| 1141 | 1118 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 // Write out all the other fields. | 1297 // Write out all the other fields. |
| 1321 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 1298 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
| 1322 writer->WriteObject(ptr()->pattern_); | 1299 writer->WriteObject(ptr()->pattern_); |
| 1323 writer->Write<intptr_t>(ptr()->type_); | 1300 writer->Write<intptr_t>(ptr()->type_); |
| 1324 writer->Write<intptr_t>(ptr()->flags_); | 1301 writer->Write<intptr_t>(ptr()->flags_); |
| 1325 | 1302 |
| 1326 // Do not write out the data part which is native. | 1303 // Do not write out the data part which is native. |
| 1327 } | 1304 } |
| 1328 | 1305 |
| 1329 } // namespace dart | 1306 } // namespace dart |
| OLD | NEW |