Chromium Code Reviews| 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 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 } | 983 } |
| 984 | 984 |
| 985 | 985 |
| 986 void RawString::WriteTo(SnapshotWriter* writer, | 986 void RawString::WriteTo(SnapshotWriter* writer, |
| 987 intptr_t object_id, | 987 intptr_t object_id, |
| 988 bool serialize_classes) { | 988 bool serialize_classes) { |
| 989 UNREACHABLE(); // String is an abstract class. | 989 UNREACHABLE(); // String is an abstract class. |
| 990 } | 990 } |
| 991 | 991 |
| 992 | 992 |
| 993 template<typename CharType, | |
| 994 typename StringType, | |
| 995 typename RawStringType, | |
| 996 typename CharAddrType, | |
| 997 typename SetHashType> | |
| 998 static RawStringType* ReadStringFrom(SnapshotReader* reader, | |
| 999 intptr_t object_id, | |
| 1000 bool classes_serialized, | |
| 1001 CharAddrType char_addr, | |
| 1002 SetHashType set_hash) { | |
| 1003 ASSERT(reader != NULL); | |
| 1004 // Read the length so that we can determine instance size to allocate. | |
| 1005 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | |
| 1006 intptr_t len = Smi::Value(smi_len); | |
| 1007 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | |
| 1008 | |
| 1009 // Set up the string object. | |
| 1010 StringType& str_obj = StringType::ZoneHandle( | |
| 1011 StringType::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | |
| 1012 for (intptr_t i = 0; i < len; i++) { | |
| 1013 *((str_obj).*(char_addr))(i) = reader->Read<CharType>(); | |
| 1014 } | |
| 1015 | |
| 1016 reader->AddBackwardReference(object_id, &str_obj); | |
| 1017 ((str_obj).*(set_hash))(Smi::Value(smi_hash)); | |
|
turnidge
2011/10/27 17:28:35
Thinking out loud... Optional...
If you wanted t
| |
| 1018 return str_obj.raw(); | |
| 1019 } | |
| 1020 | |
| 1021 | |
| 993 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1022 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 994 intptr_t object_id, | 1023 intptr_t object_id, |
| 995 bool classes_serialized) { | 1024 bool classes_serialized) { |
| 996 ASSERT(reader != NULL); | 1025 return ReadStringFrom<uint8_t, OneByteString, RawOneByteString>( |
| 997 // Read the length so that we can determine instance size to allocate. | 1026 reader, |
| 998 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1027 object_id, |
| 999 intptr_t len = Smi::Value(smi_len); | 1028 classes_serialized, |
| 1000 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | 1029 &OneByteString::CharAddr, |
| 1030 &OneByteString::SetHash); | |
| 1031 } | |
| 1001 | 1032 |
| 1002 // Set up the one byte string object. | 1033 |
| 1003 OneByteString& str_obj = OneByteString::ZoneHandle( | 1034 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1004 OneByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | 1035 intptr_t object_id, |
| 1036 bool classes_serialized) { | |
| 1037 return ReadStringFrom<uint16_t, TwoByteString, RawTwoByteString>( | |
| 1038 reader, | |
| 1039 object_id, | |
| 1040 classes_serialized, | |
| 1041 &TwoByteString::CharAddr, | |
| 1042 &TwoByteString::SetHash); | |
| 1043 } | |
| 1044 | |
| 1045 | |
| 1046 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | |
| 1047 intptr_t object_id, | |
| 1048 bool classes_serialized) { | |
| 1049 return ReadStringFrom<uint32_t, FourByteString, RawFourByteString>( | |
| 1050 reader, | |
| 1051 object_id, | |
| 1052 classes_serialized, | |
| 1053 &FourByteString::CharAddr, | |
| 1054 &FourByteString::SetHash); | |
| 1055 } | |
| 1056 | |
| 1057 | |
| 1058 template<typename CharType> | |
| 1059 static void StringWriteTo(SnapshotWriter* writer, | |
| 1060 intptr_t object_id, | |
| 1061 intptr_t class_id, | |
| 1062 bool serialize_classes, | |
| 1063 RawSmi* length, | |
| 1064 RawSmi* hash, | |
| 1065 CharType* data) { | |
| 1066 ASSERT(writer != NULL); | |
| 1067 intptr_t len = Smi::Value(length); | |
| 1068 | |
| 1069 // Write out the serialization header value for this object. | |
| 1070 writer->WriteObjectHeader(kInlined, object_id); | |
| 1071 | |
| 1072 // Write out the class information. | |
| 1073 writer->WriteObjectHeader(kObjectId, class_id); | |
| 1074 | |
| 1075 // Write out the length field. | |
| 1076 writer->Write<RawObject*>(length); | |
| 1077 | |
| 1078 // Write out the hash field. | |
| 1079 writer->Write<RawObject*>(hash); | |
| 1080 | |
| 1081 // Write out the string. | |
| 1005 for (intptr_t i = 0; i < len; i++) { | 1082 for (intptr_t i = 0; i < len; i++) { |
| 1006 *str_obj.CharAddr(i) = reader->Read<uint8_t>(); | 1083 writer->Write<CharType>(data[i]); |
| 1007 } | 1084 } |
| 1008 | |
| 1009 reader->AddBackwardReference(object_id, &str_obj); | |
| 1010 RawOneByteString* raw_str = str_obj.raw(); | |
| 1011 raw_str->ptr()->hash_ = smi_hash; | |
| 1012 return str_obj.raw(); | |
| 1013 } | 1085 } |
| 1014 | 1086 |
| 1015 | 1087 |
| 1016 void RawOneByteString::WriteTo(SnapshotWriter* writer, | 1088 void RawOneByteString::WriteTo(SnapshotWriter* writer, |
| 1017 intptr_t object_id, | 1089 intptr_t object_id, |
| 1018 bool serialize_classes) { | 1090 bool serialize_classes) { |
| 1019 ASSERT(writer != NULL); | 1091 StringWriteTo<uint8_t>(writer, |
| 1020 intptr_t len = Smi::Value(ptr()->length_); | 1092 object_id, |
| 1021 | 1093 ObjectStore::kOneByteStringClass, |
| 1022 // Write out the serialization header value for this object. | 1094 serialize_classes, |
| 1023 writer->WriteObjectHeader(kInlined, object_id); | 1095 ptr()->length_, |
| 1024 | 1096 ptr()->hash_, |
| 1025 // Write out the class information. | 1097 ptr()->data_); |
| 1026 writer->WriteObjectHeader(kObjectId, ObjectStore::kOneByteStringClass); | |
| 1027 | |
| 1028 // Write out the length field. | |
| 1029 writer->Write<RawObject*>(ptr()->length_); | |
| 1030 | |
| 1031 // Write out the hash field. | |
| 1032 writer->Write<RawObject*>(ptr()->hash_); | |
| 1033 | |
| 1034 // Write out the string. | |
| 1035 for (intptr_t i = 0; i < len; i++) { | |
| 1036 writer->Write<uint8_t>(ptr()->data_[i]); | |
| 1037 } | |
| 1038 } | |
| 1039 | |
| 1040 | |
| 1041 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | |
| 1042 intptr_t object_id, | |
| 1043 bool classes_serialized) { | |
| 1044 ASSERT(reader != NULL); | |
| 1045 // Read the length so that we can determine instance size to allocate. | |
| 1046 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | |
| 1047 intptr_t len = Smi::Value(smi_len); | |
| 1048 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | |
| 1049 | |
| 1050 // Set up the two byte string object. | |
| 1051 TwoByteString& str_obj = TwoByteString::ZoneHandle( | |
| 1052 TwoByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | |
| 1053 for (intptr_t i = 0; i < len; i++) { | |
| 1054 *str_obj.CharAddr(i) = reader->Read<uint16_t>(); | |
| 1055 } | |
| 1056 | |
| 1057 reader->AddBackwardReference(object_id, &str_obj); | |
| 1058 RawTwoByteString* raw_str = str_obj.raw(); | |
| 1059 raw_str->ptr()->hash_ = smi_hash; | |
| 1060 return str_obj.raw(); | |
| 1061 } | 1098 } |
| 1062 | 1099 |
| 1063 | 1100 |
| 1064 void RawTwoByteString::WriteTo(SnapshotWriter* writer, | 1101 void RawTwoByteString::WriteTo(SnapshotWriter* writer, |
| 1065 intptr_t object_id, | 1102 intptr_t object_id, |
| 1066 bool serialize_classes) { | 1103 bool serialize_classes) { |
| 1067 ASSERT(writer != NULL); | 1104 StringWriteTo<uint16_t>(writer, |
| 1068 intptr_t len = Smi::Value(ptr()->length_); | 1105 object_id, |
| 1069 | 1106 ObjectStore::kTwoByteStringClass, |
| 1070 // Write out the serialization header value for this object. | 1107 serialize_classes, |
| 1071 writer->WriteObjectHeader(kInlined, object_id); | 1108 ptr()->length_, |
| 1072 | 1109 ptr()->hash_, |
| 1073 // Write out the class information. | 1110 ptr()->data_); |
| 1074 writer->WriteObjectHeader(kObjectId, ObjectStore::kTwoByteStringClass); | |
| 1075 | |
| 1076 // Write out the length field. | |
| 1077 writer->Write<RawObject*>(ptr()->length_); | |
| 1078 | |
| 1079 // Write out the hash field. | |
| 1080 writer->Write<RawObject*>(ptr()->hash_); | |
| 1081 | |
| 1082 // Write out the string. | |
| 1083 for (intptr_t i = 0; i < len; i++) { | |
| 1084 writer->Write<uint16_t>(ptr()->data_[i]); | |
| 1085 } | |
| 1086 } | |
| 1087 | |
| 1088 | |
| 1089 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | |
| 1090 intptr_t object_id, | |
| 1091 bool classes_serialized) { | |
| 1092 ASSERT(reader != NULL); | |
| 1093 // Read the length so that we can determine instance size to allocate. | |
| 1094 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | |
| 1095 intptr_t len = Smi::Value(smi_len); | |
| 1096 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | |
| 1097 | |
| 1098 // Set up the four byte string object. | |
| 1099 FourByteString& str_obj = FourByteString::ZoneHandle( | |
| 1100 FourByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | |
| 1101 for (intptr_t i = 0; i < len; i++) { | |
| 1102 *str_obj.CharAddr(i) = reader->Read<uint32_t>(); | |
| 1103 } | |
| 1104 | |
| 1105 reader->AddBackwardReference(object_id, &str_obj); | |
| 1106 RawFourByteString* raw_str = str_obj.raw(); | |
| 1107 raw_str->ptr()->hash_ = smi_hash; | |
| 1108 return str_obj.raw(); | |
| 1109 } | 1111 } |
| 1110 | 1112 |
| 1111 | 1113 |
| 1112 void RawFourByteString::WriteTo(SnapshotWriter* writer, | 1114 void RawFourByteString::WriteTo(SnapshotWriter* writer, |
| 1113 intptr_t object_id, | 1115 intptr_t object_id, |
| 1114 bool serialize_classes) { | 1116 bool serialize_classes) { |
| 1115 ASSERT(writer != NULL); | 1117 StringWriteTo<uint32_t>(writer, |
| 1116 intptr_t len = Smi::Value(ptr()->length_); | 1118 object_id, |
| 1117 | 1119 ObjectStore::kFourByteStringClass, |
| 1118 // Write out the serialization header value for this object. | 1120 serialize_classes, |
| 1119 writer->WriteObjectHeader(kInlined, object_id); | 1121 ptr()->length_, |
| 1120 | 1122 ptr()->hash_, |
| 1121 // Write out the class information. | 1123 ptr()->data_); |
| 1122 writer->WriteObjectHeader(kObjectId, ObjectStore::kFourByteStringClass); | |
| 1123 | |
| 1124 // Write out the length field. | |
| 1125 writer->Write<RawObject*>(ptr()->length_); | |
| 1126 | |
| 1127 // Write out the hash field. | |
| 1128 writer->Write<RawObject*>(ptr()->hash_); | |
| 1129 | |
| 1130 // Write out the string. | |
| 1131 for (intptr_t i = 0; i < len; i++) { | |
| 1132 writer->Write<uint32_t>(ptr()->data_[i]); | |
| 1133 } | |
| 1134 } | 1124 } |
| 1135 | 1125 |
| 1136 | 1126 |
| 1137 RawBool* Bool::ReadFrom(SnapshotReader* reader, | 1127 RawBool* Bool::ReadFrom(SnapshotReader* reader, |
| 1138 intptr_t object_id, | 1128 intptr_t object_id, |
| 1139 bool classes_serialized) { | 1129 bool classes_serialized) { |
| 1140 UNREACHABLE(); | 1130 UNREACHABLE(); |
| 1141 return Bool::null(); | 1131 return Bool::null(); |
| 1142 } | 1132 } |
| 1143 | 1133 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 // Write out all the other fields. | 1312 // Write out all the other fields. |
| 1323 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 1313 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
| 1324 writer->WriteObject(ptr()->pattern_); | 1314 writer->WriteObject(ptr()->pattern_); |
| 1325 writer->Write<intptr_t>(ptr()->type_); | 1315 writer->Write<intptr_t>(ptr()->type_); |
| 1326 writer->Write<intptr_t>(ptr()->flags_); | 1316 writer->Write<intptr_t>(ptr()->flags_); |
| 1327 | 1317 |
| 1328 // Do not write out the data part which is native. | 1318 // Do not write out the data part which is native. |
| 1329 } | 1319 } |
| 1330 | 1320 |
| 1331 } // namespace dart | 1321 } // namespace dart |
| OLD | NEW |