| 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/snapshot.h" | 5 #include "vm/snapshot.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 return ReadObjectImpl(header); | 60 return ReadObjectImpl(header); |
| 61 } | 61 } |
| 62 | 62 |
| 63 | 63 |
| 64 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { | 64 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { |
| 65 ASSERT(kind_ != Snapshot::kFull); | 65 ASSERT(kind_ != Snapshot::kFull); |
| 66 // Read the class header information and lookup the class. | 66 // Read the class header information and lookup the class. |
| 67 intptr_t class_header = Read<intptr_t>(); | 67 intptr_t class_header = Read<intptr_t>(); |
| 68 ASSERT((class_header & kSmiTagMask) != 0); | 68 ASSERT((class_header & kSmiTagMask) != 0); |
| 69 Class& cls = Class::Handle(); | 69 Class& cls = Class::ZoneHandle(); |
| 70 cls ^= LookupInternalClass(class_header); | 70 cls ^= LookupInternalClass(class_header); |
| 71 AddBackwardReference(object_id, &cls); | 71 AddBackwardReference(object_id, &cls); |
| 72 if (cls.IsNull()) { | 72 if (cls.IsNull()) { |
| 73 // Read the library/class information and lookup the class. | 73 // Read the library/class information and lookup the class. |
| 74 String& library_url = String::Handle(); | 74 String& library_url = String::Handle(); |
| 75 library_url ^= ReadObjectImpl(class_header); | 75 library_url ^= ReadObjectImpl(class_header); |
| 76 String& class_name = String::Handle(); | 76 String& class_name = String::Handle(); |
| 77 class_name ^= ReadObject(); | 77 class_name ^= ReadObject(); |
| 78 const Library& library = | 78 const Library& library = |
| 79 Library::Handle(Library::LookupLibrary(library_url)); | 79 Library::Handle(Library::LookupLibrary(library_url)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 RawObject* raw = Object::Allocate(cls, instance_size, Heap::kNew); | 186 RawObject* raw = Object::Allocate(cls, instance_size, Heap::kNew); |
| 187 result ^= raw; | 187 result ^= raw; |
| 188 intptr_t offset = Object::InstanceSize(); | 188 intptr_t offset = Object::InstanceSize(); |
| 189 while (offset < instance_size) { | 189 while (offset < instance_size) { |
| 190 obj = ReadObject(); | 190 obj = ReadObject(); |
| 191 result.SetFieldAtOffset(offset, obj); | 191 result.SetFieldAtOffset(offset, obj); |
| 192 offset += kWordSize; | 192 offset += kWordSize; |
| 193 } | 193 } |
| 194 if (kind_ == Snapshot::kFull) { | 194 if (kind_ == Snapshot::kFull) { |
| 195 result.SetCreatedFromSnapshot(); | 195 result.SetCreatedFromSnapshot(); |
| 196 } else if (result.IsCanonical()) { |
| 197 result = result.Canonicalize(); |
| 196 } | 198 } |
| 197 return result.raw(); | 199 return result.raw(); |
| 198 } else { | 200 } else { |
| 199 ASSERT((class_header & kSmiTagMask) != 0); | 201 ASSERT((class_header & kSmiTagMask) != 0); |
| 200 cls ^= LookupInternalClass(class_header); | 202 cls ^= LookupInternalClass(class_header); |
| 201 ASSERT(!cls.IsNull()); | 203 ASSERT(!cls.IsNull()); |
| 202 } | 204 } |
| 203 switch (cls.instance_kind()) { | 205 switch (cls.instance_kind()) { |
| 204 #define SNAPSHOT_READ(clazz) \ | 206 #define SNAPSHOT_READ(clazz) \ |
| 205 case clazz::kInstanceKind: { \ | 207 case clazz::kInstanceKind: { \ |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 void SnapshotWriter::WriteClassId(RawClass* cls) { | 414 void SnapshotWriter::WriteClassId(RawClass* cls) { |
| 413 ASSERT(kind_ != Snapshot::kFull); | 415 ASSERT(kind_ != Snapshot::kFull); |
| 414 int id = object_store()->GetClassIndex(cls); | 416 int id = object_store()->GetClassIndex(cls); |
| 415 if (IsSingletonClassId(id) || IsObjectStoreClassId(id)) { | 417 if (IsSingletonClassId(id) || IsObjectStoreClassId(id)) { |
| 416 WriteIndexedObject(id); | 418 WriteIndexedObject(id); |
| 417 } else { | 419 } else { |
| 418 // TODO(5411462): Should restrict this to only core-lib classes in this | 420 // TODO(5411462): Should restrict this to only core-lib classes in this |
| 419 // case. | 421 // case. |
| 420 // Write out the class and tags information. | 422 // Write out the class and tags information. |
| 421 WriteObjectHeader(Object::kClassClass, cls->ptr()->tags_); | 423 WriteObjectHeader(Object::kClassClass, cls->ptr()->tags_); |
| 424 |
| 422 // Write out the library url and class name. | 425 // Write out the library url and class name. |
| 423 RawLibrary* library = cls->ptr()->library_; | 426 RawLibrary* library = cls->ptr()->library_; |
| 424 ASSERT(library != Library::null()); | 427 ASSERT(library != Library::null()); |
| 425 WriteObject(library->ptr()->url_); | 428 WriteObject(library->ptr()->url_); |
| 426 WriteObject(cls->ptr()->name_); | 429 WriteObject(cls->ptr()->name_); |
| 427 } | 430 } |
| 428 } | 431 } |
| 429 | 432 |
| 430 | 433 |
| 431 void ScriptSnapshotWriter::WriteScriptSnapshot() { | 434 void ScriptSnapshotWriter::WriteScriptSnapshot(const Library& lib) { |
| 432 // TODO(asiva): Need to implement this. | 435 ASSERT(kind() == Snapshot::kScript); |
| 433 UNIMPLEMENTED(); | 436 |
| 437 // Write out the library object. |
| 438 WriteObject(lib.raw()); |
| 439 |
| 440 // Finalize the snapshot buffer. |
| 441 FinalizeBuffer(); |
| 434 } | 442 } |
| 435 | 443 |
| 436 | 444 |
| 437 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 445 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
| 438 for (RawObject** current = first; current <= last; current++) { | 446 for (RawObject** current = first; current <= last; current++) { |
| 439 RawObject* raw_obj = *current; | 447 RawObject* raw_obj = *current; |
| 440 writer_->WriteObject(raw_obj); | 448 writer_->WriteObject(raw_obj); |
| 441 } | 449 } |
| 442 } | 450 } |
| 443 | 451 |
| 444 } // namespace dart | 452 } // namespace dart |
| OLD | NEW |