| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/symbols.h" | 9 #include "vm/symbols.h" |
| 10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 DECLARE_FLAG(bool, error_on_malformed_type); |
| 15 |
| 16 |
| 14 #define NEW_OBJECT(type) \ | 17 #define NEW_OBJECT(type) \ |
| 15 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 18 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) |
| 16 | 19 |
| 17 #define NEW_OBJECT_WITH_LEN(type, len) \ | 20 #define NEW_OBJECT_WITH_LEN(type, len) \ |
| 18 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 21 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) |
| 19 | 22 |
| 20 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ | 23 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ |
| 21 ((kind == Snapshot::kFull) ? \ | 24 ((kind == Snapshot::kFull) ? \ |
| 22 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) | 25 reader->New##type(len) : type::New(len, HEAP_SPACE(kind))) |
| 23 | 26 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 108 |
| 106 // Write out all the object pointer fields. | 109 // Write out all the object pointer fields. |
| 107 SnapshotWriterVisitor visitor(writer); | 110 SnapshotWriterVisitor visitor(writer); |
| 108 visitor.VisitPointers(from(), to()); | 111 visitor.VisitPointers(from(), to()); |
| 109 } else { | 112 } else { |
| 110 writer->WriteClassId(this); | 113 writer->WriteClassId(this); |
| 111 } | 114 } |
| 112 } | 115 } |
| 113 | 116 |
| 114 | 117 |
| 118 static const char* RawOneByteStringToCString(RawOneByteString* str) { |
| 119 const char* start = reinterpret_cast<char*>(str) - kHeapObjectTag + |
| 120 OneByteString::data_offset(); |
| 121 const int len = Smi::Value(*reinterpret_cast<RawSmi**>( |
| 122 reinterpret_cast<uword>(str) - kHeapObjectTag + String::length_offset())); |
| 123 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 124 memmove(chars, start, len); |
| 125 chars[len] = '\0'; |
| 126 return chars; |
| 127 } |
| 128 |
| 129 |
| 115 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, | 130 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, |
| 116 intptr_t object_id, | 131 intptr_t object_id, |
| 117 intptr_t tags, | 132 intptr_t tags, |
| 118 Snapshot::Kind kind) { | 133 Snapshot::Kind kind) { |
| 119 ASSERT(reader != NULL); | 134 ASSERT(reader != NULL); |
| 120 | 135 |
| 136 // Only resolved and finalized types should be written to a snapshot. |
| 137 // TODO(regis): Replace this code by an UNREACHABLE(). |
| 138 |
| 121 // Allocate parameterized type object. | 139 // Allocate parameterized type object. |
| 122 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( | 140 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( |
| 123 reader->isolate(), NEW_OBJECT(UnresolvedClass)); | 141 reader->isolate(), NEW_OBJECT(UnresolvedClass)); |
| 124 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); | 142 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); |
| 125 | 143 |
| 126 // Set the object tags. | 144 // Set the object tags. |
| 127 unresolved_class.set_tags(tags); | 145 unresolved_class.set_tags(tags); |
| 128 | 146 |
| 129 // Set all non object fields. | 147 // Set all non object fields. |
| 130 unresolved_class.set_token_pos(reader->ReadIntptrValue()); | 148 unresolved_class.set_token_pos(reader->ReadIntptrValue()); |
| 131 | 149 |
| 132 // Set all the object fields. | 150 // Set all the object fields. |
| 133 // TODO(5411462): Need to assert No GC can happen here, even though | 151 // TODO(5411462): Need to assert No GC can happen here, even though |
| 134 // allocations may happen. | 152 // allocations may happen. |
| 135 intptr_t num_flds = (unresolved_class.raw()->to() - | 153 intptr_t num_flds = (unresolved_class.raw()->to() - |
| 136 unresolved_class.raw()->from()); | 154 unresolved_class.raw()->from()); |
| 137 for (intptr_t i = 0; i <= num_flds; i++) { | 155 for (intptr_t i = 0; i <= num_flds; i++) { |
| 138 unresolved_class.StorePointer((unresolved_class.raw()->from() + i), | 156 unresolved_class.StorePointer((unresolved_class.raw()->from() + i), |
| 139 reader->ReadObjectRef()); | 157 reader->ReadObjectRef()); |
| 140 } | 158 } |
| 141 return unresolved_class.raw(); | 159 return unresolved_class.raw(); |
| 142 } | 160 } |
| 143 | 161 |
| 144 | 162 |
| 145 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, | 163 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, |
| 146 intptr_t object_id, | 164 intptr_t object_id, |
| 147 Snapshot::Kind kind) { | 165 Snapshot::Kind kind) { |
| 148 ASSERT(writer != NULL); | 166 ASSERT(writer != NULL); |
| 149 | 167 |
| 168 // Only resolved and finalized types should be written to a snapshot. |
| 169 // TODO(regis): Replace this code by an UNREACHABLE(). |
| 170 if (FLAG_error_on_malformed_type) { |
| 171 // Print the name of the unresolved class, as well as the token location |
| 172 // from where it is referred to, making sure not to allocate any handles. |
| 173 // Unfortunately, we cannot print the script name. |
| 174 OS::Print("Snapshotting unresolved class '%s' at token pos %"Pd"\n", |
| 175 RawOneByteStringToCString( |
| 176 reinterpret_cast<RawOneByteString*>(ptr()->ident_)), |
| 177 ptr()->token_pos_); |
| 178 UNREACHABLE(); |
| 179 } |
| 180 |
| 150 // Write out the serialization header value for this object. | 181 // Write out the serialization header value for this object. |
| 151 writer->WriteInlinedObjectHeader(object_id); | 182 writer->WriteInlinedObjectHeader(object_id); |
| 152 | 183 |
| 153 // Write out the class and tags information. | 184 // Write out the class and tags information. |
| 154 writer->WriteVMIsolateObject(kUnresolvedClassCid); | 185 writer->WriteVMIsolateObject(kUnresolvedClassCid); |
| 155 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 186 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 156 | 187 |
| 157 // Write out all the non object pointer fields. | 188 // Write out all the non object pointer fields. |
| 158 writer->WriteIntptrValue(ptr()->token_pos_); | 189 writer->WriteIntptrValue(ptr()->token_pos_); |
| 159 | 190 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 243 |
| 213 return type.raw(); | 244 return type.raw(); |
| 214 } | 245 } |
| 215 | 246 |
| 216 | 247 |
| 217 void RawType::WriteTo(SnapshotWriter* writer, | 248 void RawType::WriteTo(SnapshotWriter* writer, |
| 218 intptr_t object_id, | 249 intptr_t object_id, |
| 219 Snapshot::Kind kind) { | 250 Snapshot::Kind kind) { |
| 220 ASSERT(writer != NULL); | 251 ASSERT(writer != NULL); |
| 221 | 252 |
| 253 // Only resolved and finalized types should be written to a snapshot. |
| 254 // TODO(regis): Replace the test below by an ASSERT(). |
| 255 if (FLAG_error_on_malformed_type && |
| 256 (ptr()->type_state_ != RawType::kFinalizedInstantiated) && |
| 257 (ptr()->type_state_ != RawType::kFinalizedUninstantiated)) { |
| 258 // Print the name of the class of the unfinalized type, as well as the |
| 259 // token location from where it is referred to, making sure not |
| 260 // to allocate any handles. Unfortunately, we cannot print the script name. |
| 261 const intptr_t cid = ClassIdTag::decode(*reinterpret_cast<uword*>( |
| 262 reinterpret_cast<uword>(ptr()->type_class_) - kHeapObjectTag + |
| 263 Object::tags_offset())); |
| 264 if (cid == kUnresolvedClassCid) { |
| 265 OS::Print("Snapshotting unresolved type '%s' at token pos %"Pd"\n", |
| 266 RawOneByteStringToCString( |
| 267 reinterpret_cast<RawOneByteString*>( |
| 268 reinterpret_cast<RawUnresolvedClass*>( |
| 269 ptr()->type_class_)->ptr()->ident_)), |
| 270 ptr()->token_pos_); |
| 271 } else { |
| 272 // Assume cid == kClassId, but it can also be kIllegalCid. |
| 273 OS::Print("Snapshotting unfinalized type '%s' at token pos %"Pd"\n", |
| 274 RawOneByteStringToCString( |
| 275 reinterpret_cast<RawOneByteString*>( |
| 276 reinterpret_cast<RawClass*>( |
| 277 ptr()->type_class_)->ptr()->name_)), |
| 278 ptr()->token_pos_); |
| 279 } |
| 280 UNREACHABLE(); |
| 281 } |
| 282 |
| 222 // Write out the serialization header value for this object. | 283 // Write out the serialization header value for this object. |
| 223 writer->WriteInlinedObjectHeader(object_id); | 284 writer->WriteInlinedObjectHeader(object_id); |
| 224 | 285 |
| 225 // Write out the class and tags information. | 286 // Write out the class and tags information. |
| 226 writer->WriteIndexedObject(kTypeCid); | 287 writer->WriteIndexedObject(kTypeCid); |
| 227 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 288 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 228 | 289 |
| 229 // Write out all the non object pointer fields. | 290 // Write out all the non object pointer fields. |
| 230 writer->WriteIntptrValue(ptr()->token_pos_); | 291 writer->WriteIntptrValue(ptr()->token_pos_); |
| 231 writer->Write<int8_t>(ptr()->type_state_); | 292 writer->Write<int8_t>(ptr()->type_state_); |
| 232 | 293 |
| 233 // Write out all the object pointer fields. | 294 // Write out all the object pointer fields. |
| 234 SnapshotWriterVisitor visitor(writer); | 295 SnapshotWriterVisitor visitor(writer); |
| 235 visitor.VisitPointers(from(), to()); | 296 visitor.VisitPointers(from(), to()); |
| 236 } | 297 } |
| 237 | 298 |
| 238 | 299 |
| 239 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, | 300 RawTypeParameter* TypeParameter::ReadFrom(SnapshotReader* reader, |
| 240 intptr_t object_id, | 301 intptr_t object_id, |
| 241 intptr_t tags, | 302 intptr_t tags, |
| 242 Snapshot::Kind kind) { | 303 Snapshot::Kind kind) { |
| 243 ASSERT(reader != NULL); | 304 ASSERT(reader != NULL); |
| 244 | 305 |
| 245 // Allocate type parameter object. | 306 // Allocate type parameter object. |
| 246 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 307 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 247 reader->isolate(), NEW_OBJECT(TypeParameter)); | 308 reader->isolate(), NEW_OBJECT(TypeParameter)); |
| 248 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized); | 309 reader->AddBackRef(object_id, &type_parameter, kIsDeserialized); |
| 249 | 310 |
| 250 // Set the object tags. | 311 // Set the object tags. |
| 251 type_parameter.set_tags(tags); | 312 type_parameter.set_tags(tags); |
| 252 | 313 |
| 253 // Set all non object fields. | 314 // Set all non object fields. |
| 254 type_parameter.set_index(reader->ReadIntptrValue()); | 315 type_parameter.set_index(reader->ReadIntptrValue()); |
| 255 type_parameter.set_token_pos(reader->ReadIntptrValue()); | 316 type_parameter.set_token_pos(reader->ReadIntptrValue()); |
| 256 type_parameter.set_type_state(reader->Read<int8_t>()); | 317 type_parameter.set_type_state(reader->Read<int8_t>()); |
| 257 | 318 |
| 258 // Set all the object fields. | 319 // Set all the object fields. |
| 259 // TODO(5411462): Need to assert No GC can happen here, even though | 320 // TODO(5411462): Need to assert No GC can happen here, even though |
| 260 // allocations may happen. | 321 // allocations may happen. |
| 261 intptr_t num_flds = (type_parameter.raw()->to() - | 322 intptr_t num_flds = (type_parameter.raw()->to() - |
| 262 type_parameter.raw()->from()); | 323 type_parameter.raw()->from()); |
| 263 for (intptr_t i = 0; i <= num_flds; i++) { | 324 for (intptr_t i = 0; i <= num_flds; i++) { |
| 264 type_parameter.StorePointer((type_parameter.raw()->from() + i), | 325 type_parameter.StorePointer((type_parameter.raw()->from() + i), |
| 265 reader->ReadObjectRef()); | 326 reader->ReadObjectRef()); |
| 266 } | 327 } |
| 267 | 328 |
| 268 return type_parameter.raw(); | 329 return type_parameter.raw(); |
| 269 } | 330 } |
| 270 | 331 |
| 271 | 332 |
| 272 void RawTypeParameter::WriteTo(SnapshotWriter* writer, | 333 void RawTypeParameter::WriteTo(SnapshotWriter* writer, |
| 273 intptr_t object_id, | 334 intptr_t object_id, |
| 274 Snapshot::Kind kind) { | 335 Snapshot::Kind kind) { |
| 275 ASSERT(writer != NULL); | 336 ASSERT(writer != NULL); |
| 276 | 337 |
| 338 // Only finalized type parameters should be written to a snapshot. |
| 339 // TODO(regis): Replace the test below by an ASSERT(). |
| 340 if (FLAG_error_on_malformed_type && |
| 341 (ptr()->type_state_ != RawTypeParameter::kFinalizedUninstantiated)) { |
| 342 // Print the name of the unfinalized type parameter, the name of the class |
| 343 // it parameterizes, as well as the token location from where it is referred |
| 344 // to, making sure not to allocate any handles. Unfortunately, we cannot |
| 345 // print the script name. |
| 346 OS::Print("Snapshotting unfinalized type parameter '%s' of class '%s' at " |
| 347 "token pos %"Pd"\n", |
| 348 RawOneByteStringToCString( |
| 349 reinterpret_cast<RawOneByteString*>(ptr()->name_)), |
| 350 RawOneByteStringToCString( |
| 351 reinterpret_cast<RawOneByteString*>( |
| 352 reinterpret_cast<RawClass*>( |
| 353 ptr()->parameterized_class_)->ptr()->name_)), |
| 354 ptr()->token_pos_); |
| 355 UNREACHABLE(); |
| 356 } |
| 357 |
| 277 // Write out the serialization header value for this object. | 358 // Write out the serialization header value for this object. |
| 278 writer->WriteInlinedObjectHeader(object_id); | 359 writer->WriteInlinedObjectHeader(object_id); |
| 279 | 360 |
| 280 // Write out the class and tags information. | 361 // Write out the class and tags information. |
| 281 writer->WriteIndexedObject(kTypeParameterCid); | 362 writer->WriteIndexedObject(kTypeParameterCid); |
| 282 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 363 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 283 | 364 |
| 284 // Write out all the non object pointer fields. | 365 // Write out all the non object pointer fields. |
| 285 writer->WriteIntptrValue(ptr()->index_); | 366 writer->WriteIntptrValue(ptr()->index_); |
| 286 writer->WriteIntptrValue(ptr()->token_pos_); | 367 writer->WriteIntptrValue(ptr()->token_pos_); |
| (...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2244 // Write out the class and tags information. | 2325 // Write out the class and tags information. |
| 2245 writer->WriteIndexedObject(kWeakPropertyCid); | 2326 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2246 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2327 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2247 | 2328 |
| 2248 // Write out all the other fields. | 2329 // Write out all the other fields. |
| 2249 writer->Write<RawObject*>(ptr()->key_); | 2330 writer->Write<RawObject*>(ptr()->key_); |
| 2250 writer->Write<RawObject*>(ptr()->value_); | 2331 writer->Write<RawObject*>(ptr()->value_); |
| 2251 } | 2332 } |
| 2252 | 2333 |
| 2253 } // namespace dart | 2334 } // namespace dart |
| OLD | NEW |