Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: vm/snapshot.cc

Issue 9166012: Create temporary handles in the snapshot object during initialization and use them instead of cre... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/snapshot.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 ASSERT(kLengthIndex == length_offset()); 45 ASSERT(kLengthIndex == length_offset());
46 ASSERT((kSnapshotFlagIndex * sizeof(int32_t)) == kind_offset()); 46 ASSERT((kSnapshotFlagIndex * sizeof(int32_t)) == kind_offset());
47 ASSERT((kHeapObjectTag & kInlined)); 47 ASSERT((kHeapObjectTag & kInlined));
48 ASSERT((kHeapObjectTag & kObjectId)); 48 ASSERT((kHeapObjectTag & kObjectId));
49 ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId); 49 ASSERT((kObjectAlignmentMask & kObjectId) == kObjectId);
50 const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory); 50 const Snapshot* snapshot = reinterpret_cast<const Snapshot*>(raw_memory);
51 return snapshot; 51 return snapshot;
52 } 52 }
53 53
54 54
55 SnapshotReader::SnapshotReader(const Snapshot* snapshot, Isolate* isolate)
56 : stream_(snapshot->content(), snapshot->length()),
57 kind_(snapshot->kind()),
58 isolate_(isolate),
59 cls_(Class::Handle()),
60 obj_(Object::Handle()),
61 str_(String::Handle()),
62 library_(Library::Handle()),
63 type_(AbstractType::Handle()),
64 type_arguments_(AbstractTypeArguments::Handle()),
65 backward_references_() {
66 }
67
68
55 RawObject* SnapshotReader::ReadObject() { 69 RawObject* SnapshotReader::ReadObject() {
56 int64_t value = Read<int64_t>(); 70 int64_t value = Read<int64_t>();
57 if ((value & kSmiTagMask) == 0) { 71 if ((value & kSmiTagMask) == 0) {
58 return Integer::New((value >> kSmiTagShift)); 72 return Integer::New((value >> kSmiTagShift));
59 } 73 }
60 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); 74 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
61 return ReadObjectImpl(value); 75 return ReadObjectImpl(value);
62 } 76 }
63 77
64 78
65 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { 79 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) {
66 ASSERT(kind_ != Snapshot::kFull); 80 ASSERT(kind_ != Snapshot::kFull);
67 // Read the class header information and lookup the class. 81 // Read the class header information and lookup the class.
68 intptr_t class_header = ReadIntptrValue(); 82 intptr_t class_header = ReadIntptrValue();
69 ASSERT((class_header & kSmiTagMask) != 0); 83 ASSERT((class_header & kSmiTagMask) != 0);
70 Class& cls = Class::ZoneHandle(isolate(), Class::null()); 84 Class& cls = Class::ZoneHandle(isolate(), Class::null());
71 cls ^= LookupInternalClass(class_header); 85 cls ^= LookupInternalClass(class_header);
72 AddBackwardReference(object_id, &cls); 86 AddBackwardReference(object_id, &cls);
73 if (cls.IsNull()) { 87 if (cls.IsNull()) {
74 // Read the library/class information and lookup the class. 88 // Read the library/class information and lookup the class.
75 String& library_url = String::Handle(isolate(), String::null()); 89 str_ ^= ReadObjectImpl(class_header);
76 library_url ^= ReadObjectImpl(class_header); 90 library_ = Library::LookupLibrary(str_);
77 String& class_name = String::Handle(isolate(), String::null()); 91 ASSERT(!library_.IsNull());
78 class_name ^= ReadObject(); 92 str_ ^= ReadObject();
79 const Library& library = 93 cls ^= library_.LookupClass(str_);
80 Library::Handle(isolate(), Library::LookupLibrary(library_url));
81 ASSERT(!library.IsNull());
82 cls ^= library.LookupClass(class_name);
83 } 94 }
84 ASSERT(!cls.IsNull()); 95 ASSERT(!cls.IsNull());
85 return cls.raw(); 96 return cls.raw();
86 } 97 }
87 98
88 99
89 void SnapshotReader::AddBackwardReference(intptr_t id, Object* obj) { 100 void SnapshotReader::AddBackwardReference(intptr_t id, Object* obj) {
90 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); 101 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length());
91 backward_references_.Add(obj); 102 backward_references_.Add(obj);
92 } 103 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 intptr_t index = object_id - kMaxPredefinedObjectIds; 176 intptr_t index = object_id - kMaxPredefinedObjectIds;
166 ASSERT(index < backward_references_.length()); 177 ASSERT(index < backward_references_.length());
167 return backward_references_[index]->raw(); 178 return backward_references_[index]->raw();
168 } 179 }
169 180
170 181
171 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { 182 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) {
172 // Read the class header information and lookup the class. 183 // Read the class header information and lookup the class.
173 intptr_t class_header = ReadIntptrValue(); 184 intptr_t class_header = ReadIntptrValue();
174 intptr_t tags = ReadIntptrValue(); 185 intptr_t tags = ReadIntptrValue();
175 Class& cls = Class::Handle(isolate(), Class::null());
176 Object& obj = Object::Handle(isolate(), Object::null());
177 if (SerializedHeaderData::decode(class_header) == kInstanceId) { 186 if (SerializedHeaderData::decode(class_header) == kInstanceId) {
178 // Object is regular dart instance. 187 // Object is regular dart instance.
179 Instance& result = Instance::ZoneHandle(isolate(), Instance::null()); 188 Instance& result = Instance::ZoneHandle(isolate(), Instance::null());
180 AddBackwardReference(object_id, &result); 189 AddBackwardReference(object_id, &result);
181 190
182 cls ^= ReadObject(); 191 cls_ ^= ReadObject();
183 ASSERT(!cls.IsNull()); 192 ASSERT(!cls_.IsNull());
184 intptr_t instance_size = cls.instance_size(); 193 intptr_t instance_size = cls_.instance_size();
185 ASSERT(instance_size > 0); 194 ASSERT(instance_size > 0);
186 // Allocate the instance and read in all the fields for the object. 195 // Allocate the instance and read in all the fields for the object.
187 RawObject* raw = Object::Allocate(cls, instance_size, Heap::kNew); 196 RawObject* raw = Object::Allocate(cls_, instance_size, Heap::kNew);
188 result ^= raw; 197 result ^= raw;
189 intptr_t offset = Object::InstanceSize(); 198 intptr_t offset = Object::InstanceSize();
190 while (offset < instance_size) { 199 while (offset < instance_size) {
191 obj = ReadObject(); 200 obj_ = ReadObject();
192 result.SetFieldAtOffset(offset, obj); 201 result.SetFieldAtOffset(offset, obj_);
193 offset += kWordSize; 202 offset += kWordSize;
194 } 203 }
195 if (kind_ == Snapshot::kFull) { 204 if (kind_ == Snapshot::kFull) {
196 result.SetCreatedFromSnapshot(); 205 result.SetCreatedFromSnapshot();
197 } else if (result.IsCanonical()) { 206 } else if (result.IsCanonical()) {
198 result = result.Canonicalize(); 207 result = result.Canonicalize();
199 } 208 }
200 return result.raw(); 209 return result.raw();
201 } else { 210 } else {
202 ASSERT((class_header & kSmiTagMask) != 0); 211 ASSERT((class_header & kSmiTagMask) != 0);
203 cls ^= LookupInternalClass(class_header); 212 cls_ ^= LookupInternalClass(class_header);
204 ASSERT(!cls.IsNull()); 213 ASSERT(!cls_.IsNull());
205 } 214 }
206 switch (cls.instance_kind()) { 215 switch (cls_.instance_kind()) {
207 #define SNAPSHOT_READ(clazz) \ 216 #define SNAPSHOT_READ(clazz) \
208 case clazz::kInstanceKind: { \ 217 case clazz::kInstanceKind: { \
209 obj = clazz::ReadFrom(this, object_id, tags, kind_); \ 218 obj_ = clazz::ReadFrom(this, object_id, tags, kind_); \
210 break; \ 219 break; \
211 } 220 }
212 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) 221 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ)
213 #undef SNAPSHOT_READ 222 #undef SNAPSHOT_READ
214 default: UNREACHABLE(); break; 223 default: UNREACHABLE(); break;
215 } 224 }
216 if (kind_ == Snapshot::kFull) { 225 if (kind_ == Snapshot::kFull) {
217 obj.SetCreatedFromSnapshot(); 226 obj_.SetCreatedFromSnapshot();
218 } 227 }
219 return obj.raw(); 228 return obj_.raw();
220 } 229 }
221 230
222 231
223 void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { 232 void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) {
224 // Write out the serialization header value for this object. 233 // Write out the serialization header value for this object.
225 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); 234 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds);
226 235
227 // Write out the class and tags information. 236 // Write out the class and tags information.
228 WriteObjectHeader(ObjectStore::kArrayClass, 0); 237 WriteObjectHeader(ObjectStore::kArrayClass, 0);
229 238
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 454
446 455
447 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { 456 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
448 for (RawObject** current = first; current <= last; current++) { 457 for (RawObject** current = first; current <= last; current++) {
449 RawObject* raw_obj = *current; 458 RawObject* raw_obj = *current;
450 writer_->WriteObject(raw_obj); 459 writer_->WriteObject(raw_obj);
451 } 460 }
452 } 461 }
453 462
454 } // namespace dart 463 } // namespace dart
OLDNEW
« no previous file with comments | « vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698