| 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" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 // Write out all the object pointer fields. | 109 // Write out all the object pointer fields. |
| 110 SnapshotWriterVisitor visitor(writer); | 110 SnapshotWriterVisitor visitor(writer); |
| 111 visitor.VisitPointers(from(), to()); | 111 visitor.VisitPointers(from(), to()); |
| 112 } else { | 112 } else { |
| 113 writer->WriteClassId(this); | 113 writer->WriteClassId(this); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 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 | |
| 130 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, | 118 RawUnresolvedClass* UnresolvedClass::ReadFrom(SnapshotReader* reader, |
| 131 intptr_t object_id, | 119 intptr_t object_id, |
| 132 intptr_t tags, | 120 intptr_t tags, |
| 133 Snapshot::Kind kind) { | 121 Snapshot::Kind kind) { |
| 134 ASSERT(reader != NULL); | 122 ASSERT(reader != NULL); |
| 135 | 123 |
| 136 // Only resolved and finalized types should be written to a snapshot. | 124 // Allocate unresolved class object. |
| 137 // TODO(regis): Replace this code by an UNREACHABLE(). | |
| 138 | |
| 139 // Allocate parameterized type object. | |
| 140 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( | 125 UnresolvedClass& unresolved_class = UnresolvedClass::ZoneHandle( |
| 141 reader->isolate(), NEW_OBJECT(UnresolvedClass)); | 126 reader->isolate(), NEW_OBJECT(UnresolvedClass)); |
| 142 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); | 127 reader->AddBackRef(object_id, &unresolved_class, kIsDeserialized); |
| 143 | 128 |
| 144 // Set the object tags. | 129 // Set the object tags. |
| 145 unresolved_class.set_tags(tags); | 130 unresolved_class.set_tags(tags); |
| 146 | 131 |
| 147 // Set all non object fields. | 132 // Set all non object fields. |
| 148 unresolved_class.set_token_pos(reader->ReadIntptrValue()); | 133 unresolved_class.set_token_pos(reader->ReadIntptrValue()); |
| 149 | 134 |
| 150 // Set all the object fields. | 135 // Set all the object fields. |
| 151 // TODO(5411462): Need to assert No GC can happen here, even though | 136 // TODO(5411462): Need to assert No GC can happen here, even though |
| 152 // allocations may happen. | 137 // allocations may happen. |
| 153 intptr_t num_flds = (unresolved_class.raw()->to() - | 138 intptr_t num_flds = (unresolved_class.raw()->to() - |
| 154 unresolved_class.raw()->from()); | 139 unresolved_class.raw()->from()); |
| 155 for (intptr_t i = 0; i <= num_flds; i++) { | 140 for (intptr_t i = 0; i <= num_flds; i++) { |
| 156 unresolved_class.StorePointer((unresolved_class.raw()->from() + i), | 141 unresolved_class.StorePointer((unresolved_class.raw()->from() + i), |
| 157 reader->ReadObjectRef()); | 142 reader->ReadObjectRef()); |
| 158 } | 143 } |
| 159 return unresolved_class.raw(); | 144 return unresolved_class.raw(); |
| 160 } | 145 } |
| 161 | 146 |
| 162 | 147 |
| 163 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, | 148 void RawUnresolvedClass::WriteTo(SnapshotWriter* writer, |
| 164 intptr_t object_id, | 149 intptr_t object_id, |
| 165 Snapshot::Kind kind) { | 150 Snapshot::Kind kind) { |
| 166 ASSERT(writer != NULL); | 151 ASSERT(writer != NULL); |
| 167 | 152 |
| 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 | |
| 181 // Write out the serialization header value for this object. | 153 // Write out the serialization header value for this object. |
| 182 writer->WriteInlinedObjectHeader(object_id); | 154 writer->WriteInlinedObjectHeader(object_id); |
| 183 | 155 |
| 184 // Write out the class and tags information. | 156 // Write out the class and tags information. |
| 185 writer->WriteVMIsolateObject(kUnresolvedClassCid); | 157 writer->WriteVMIsolateObject(kUnresolvedClassCid); |
| 186 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 158 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 187 | 159 |
| 188 // Write out all the non object pointer fields. | 160 // Write out all the non object pointer fields. |
| 189 writer->WriteIntptrValue(ptr()->token_pos_); | 161 writer->WriteIntptrValue(ptr()->token_pos_); |
| 190 | 162 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 210 } |
| 239 | 211 |
| 240 // Set the object tags (This is done after 'Canonicalize', which | 212 // Set the object tags (This is done after 'Canonicalize', which |
| 241 // does not canonicalize a type already marked as canonical). | 213 // does not canonicalize a type already marked as canonical). |
| 242 type.set_tags(tags); | 214 type.set_tags(tags); |
| 243 | 215 |
| 244 return type.raw(); | 216 return type.raw(); |
| 245 } | 217 } |
| 246 | 218 |
| 247 | 219 |
| 220 static const char* RawOneByteStringToCString(RawOneByteString* str) { |
| 221 const char* start = reinterpret_cast<char*>(str) - kHeapObjectTag + |
| 222 OneByteString::data_offset(); |
| 223 const int len = Smi::Value(*reinterpret_cast<RawSmi**>( |
| 224 reinterpret_cast<uword>(str) - kHeapObjectTag + String::length_offset())); |
| 225 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 226 memmove(chars, start, len); |
| 227 chars[len] = '\0'; |
| 228 return chars; |
| 229 } |
| 230 |
| 231 |
| 248 void RawType::WriteTo(SnapshotWriter* writer, | 232 void RawType::WriteTo(SnapshotWriter* writer, |
| 249 intptr_t object_id, | 233 intptr_t object_id, |
| 250 Snapshot::Kind kind) { | 234 Snapshot::Kind kind) { |
| 251 ASSERT(writer != NULL); | 235 ASSERT(writer != NULL); |
| 252 | 236 |
| 253 // Only resolved and finalized types should be written to a snapshot. | 237 // Only resolved and finalized types should be written to a snapshot. |
| 254 // TODO(regis): Replace the test below by an ASSERT(). | 238 // TODO(regis): Replace the test below by an ASSERT() or remove the flag test. |
| 255 if (FLAG_error_on_malformed_type && | 239 if (FLAG_error_on_malformed_type && |
| 256 (ptr()->type_state_ != RawType::kFinalizedInstantiated) && | 240 (ptr()->type_state_ != RawType::kFinalizedInstantiated) && |
| 257 (ptr()->type_state_ != RawType::kFinalizedUninstantiated)) { | 241 (ptr()->type_state_ != RawType::kFinalizedUninstantiated)) { |
| 258 // Print the name of the class of the unfinalized type, as well as the | 242 // 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 | 243 // token location from where it is referred to, making sure not |
| 260 // to allocate any handles. Unfortunately, we cannot print the script name. | 244 // to allocate any handles. Unfortunately, we cannot print the script name. |
| 261 const intptr_t cid = ClassIdTag::decode(*reinterpret_cast<uword*>( | 245 const intptr_t cid = ClassIdTag::decode(*reinterpret_cast<uword*>( |
| 262 reinterpret_cast<uword>(ptr()->type_class_) - kHeapObjectTag + | 246 reinterpret_cast<uword>(ptr()->type_class_) - kHeapObjectTag + |
| 263 Object::tags_offset())); | 247 Object::tags_offset())); |
| 264 if (cid == kUnresolvedClassCid) { | 248 if (cid == kUnresolvedClassCid) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return type_parameter.raw(); | 313 return type_parameter.raw(); |
| 330 } | 314 } |
| 331 | 315 |
| 332 | 316 |
| 333 void RawTypeParameter::WriteTo(SnapshotWriter* writer, | 317 void RawTypeParameter::WriteTo(SnapshotWriter* writer, |
| 334 intptr_t object_id, | 318 intptr_t object_id, |
| 335 Snapshot::Kind kind) { | 319 Snapshot::Kind kind) { |
| 336 ASSERT(writer != NULL); | 320 ASSERT(writer != NULL); |
| 337 | 321 |
| 338 // Only finalized type parameters should be written to a snapshot. | 322 // Only finalized type parameters should be written to a snapshot. |
| 339 // TODO(regis): Replace the test below by an ASSERT(). | 323 // TODO(regis): Replace the test below by an ASSERT() or remove the flag test. |
| 340 if (FLAG_error_on_malformed_type && | 324 if (FLAG_error_on_malformed_type && |
| 341 (ptr()->type_state_ != RawTypeParameter::kFinalizedUninstantiated)) { | 325 (ptr()->type_state_ != RawTypeParameter::kFinalizedUninstantiated)) { |
| 342 // Print the name of the unfinalized type parameter, the name of the class | 326 // 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 | 327 // 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 | 328 // to, making sure not to allocate any handles. Unfortunately, we cannot |
| 345 // print the script name. | 329 // print the script name. |
| 346 OS::Print("Snapshotting unfinalized type parameter '%s' of class '%s' at " | 330 OS::Print("Snapshotting unfinalized type parameter '%s' of class '%s' at " |
| 347 "token pos %"Pd"\n", | 331 "token pos %"Pd"\n", |
| 348 RawOneByteStringToCString( | 332 RawOneByteStringToCString( |
| 349 reinterpret_cast<RawOneByteString*>(ptr()->name_)), | 333 reinterpret_cast<RawOneByteString*>(ptr()->name_)), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 366 writer->WriteIntptrValue(ptr()->index_); | 350 writer->WriteIntptrValue(ptr()->index_); |
| 367 writer->WriteIntptrValue(ptr()->token_pos_); | 351 writer->WriteIntptrValue(ptr()->token_pos_); |
| 368 writer->Write<int8_t>(ptr()->type_state_); | 352 writer->Write<int8_t>(ptr()->type_state_); |
| 369 | 353 |
| 370 // Write out all the object pointer fields. | 354 // Write out all the object pointer fields. |
| 371 SnapshotWriterVisitor visitor(writer); | 355 SnapshotWriterVisitor visitor(writer); |
| 372 visitor.VisitPointers(from(), to()); | 356 visitor.VisitPointers(from(), to()); |
| 373 } | 357 } |
| 374 | 358 |
| 375 | 359 |
| 360 RawBoundedType* BoundedType::ReadFrom(SnapshotReader* reader, |
| 361 intptr_t object_id, |
| 362 intptr_t tags, |
| 363 Snapshot::Kind kind) { |
| 364 ASSERT(reader != NULL); |
| 365 |
| 366 // Allocate bounded type object. |
| 367 BoundedType& bounded_type = BoundedType::ZoneHandle( |
| 368 reader->isolate(), NEW_OBJECT(BoundedType)); |
| 369 reader->AddBackRef(object_id, &bounded_type, kIsDeserialized); |
| 370 |
| 371 // Set the object tags. |
| 372 bounded_type.set_tags(tags); |
| 373 |
| 374 // Set all the object fields. |
| 375 // TODO(5411462): Need to assert No GC can happen here, even though |
| 376 // allocations may happen. |
| 377 intptr_t num_flds = (bounded_type.raw()->to() - |
| 378 bounded_type.raw()->from()); |
| 379 for (intptr_t i = 0; i <= num_flds; i++) { |
| 380 bounded_type.StorePointer((bounded_type.raw()->from() + i), |
| 381 reader->ReadObjectRef()); |
| 382 } |
| 383 |
| 384 bounded_type.set_is_being_checked(false); |
| 385 |
| 386 return bounded_type.raw(); |
| 387 } |
| 388 |
| 389 |
| 390 void RawBoundedType::WriteTo(SnapshotWriter* writer, |
| 391 intptr_t object_id, |
| 392 Snapshot::Kind kind) { |
| 393 ASSERT(writer != NULL); |
| 394 |
| 395 // Write out the serialization header value for this object. |
| 396 writer->WriteInlinedObjectHeader(object_id); |
| 397 |
| 398 // Write out the class and tags information. |
| 399 writer->WriteIndexedObject(kBoundedTypeCid); |
| 400 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 401 |
| 402 // Write out all the object pointer fields. |
| 403 SnapshotWriterVisitor visitor(writer); |
| 404 visitor.VisitPointers(from(), to()); |
| 405 } |
| 406 |
| 407 |
| 376 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom( | 408 RawAbstractTypeArguments* AbstractTypeArguments::ReadFrom( |
| 377 SnapshotReader* reader, | 409 SnapshotReader* reader, |
| 378 intptr_t object_id, | 410 intptr_t object_id, |
| 379 intptr_t tags, | 411 intptr_t tags, |
| 380 Snapshot::Kind kind) { | 412 Snapshot::Kind kind) { |
| 381 UNREACHABLE(); // AbstractTypeArguments is an abstract class. | 413 UNREACHABLE(); // AbstractTypeArguments is an abstract class. |
| 382 return TypeArguments::null(); | 414 return TypeArguments::null(); |
| 383 } | 415 } |
| 384 | 416 |
| 385 | 417 |
| (...skipping 2147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2533 // Write out the class and tags information. | 2565 // Write out the class and tags information. |
| 2534 writer->WriteIndexedObject(kWeakPropertyCid); | 2566 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2535 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2567 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2536 | 2568 |
| 2537 // Write out all the other fields. | 2569 // Write out all the other fields. |
| 2538 writer->Write<RawObject*>(ptr()->key_); | 2570 writer->Write<RawObject*>(ptr()->key_); |
| 2539 writer->Write<RawObject*>(ptr()->value_); | 2571 writer->Write<RawObject*>(ptr()->value_); |
| 2540 } | 2572 } |
| 2541 | 2573 |
| 2542 } // namespace dart | 2574 } // namespace dart |
| OLD | NEW |