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

Side by Side Diff: vm/snapshot.cc

Issue 9021042: Make snapshots 32 or 64 bit compliant by using Write<int64_t> and Read<int64_t> for intptr_t type... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 8 years, 12 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
« vm/snapshot.h ('K') | « 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 RawObject* SnapshotReader::ReadObject() { 55 RawObject* SnapshotReader::ReadObject() {
56 intptr_t header = Read<intptr_t>(); 56 int64_t value = Read<int64_t>();
57 if ((header & kSmiTagMask) == 0) { 57 if ((value & kSmiTagMask) == 0) {
58 return reinterpret_cast<RawObject*>(header); 58 return Integer::New((value >> kSmiTagShift));
59 } 59 }
60 return ReadObjectImpl(header); 60 ASSERT((value <= LONG_MAX) && (value >= LONG_MIN));
Ivan Posva 2011/12/27 22:27:59 ditto
siva 2011/12/27 23:47:20 Done.
61 return ReadObjectImpl(value);
61 } 62 }
62 63
63 64
64 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) { 65 RawClass* SnapshotReader::ReadClassId(intptr_t object_id) {
65 ASSERT(kind_ != Snapshot::kFull); 66 ASSERT(kind_ != Snapshot::kFull);
66 // Read the class header information and lookup the class. 67 // Read the class header information and lookup the class.
67 intptr_t class_header = Read<intptr_t>(); 68 intptr_t class_header = ReadIntptrValue();
68 ASSERT((class_header & kSmiTagMask) != 0); 69 ASSERT((class_header & kSmiTagMask) != 0);
69 Class& cls = Class::ZoneHandle(); 70 Class& cls = Class::ZoneHandle();
70 cls ^= LookupInternalClass(class_header); 71 cls ^= LookupInternalClass(class_header);
71 AddBackwardReference(object_id, &cls); 72 AddBackwardReference(object_id, &cls);
72 if (cls.IsNull()) { 73 if (cls.IsNull()) {
73 // Read the library/class information and lookup the class. 74 // Read the library/class information and lookup the class.
74 String& library_url = String::Handle(); 75 String& library_url = String::Handle();
75 library_url ^= ReadObjectImpl(class_header); 76 library_url ^= ReadObjectImpl(class_header);
76 String& class_name = String::Handle(); 77 String& class_name = String::Handle();
77 class_name ^= ReadObject(); 78 class_name ^= ReadObject();
(...skipping 26 matching lines...) Expand all
104 *(object_store->from() + i) = ReadObject(); 105 *(object_store->from() + i) = ReadObject();
105 } 106 }
106 107
107 // Setup native resolver for bootstrap impl. 108 // Setup native resolver for bootstrap impl.
108 Bootstrap::SetupNativeResolver(); 109 Bootstrap::SetupNativeResolver();
109 } 110 }
110 111
111 112
112 RawClass* SnapshotReader::LookupInternalClass(intptr_t class_header) { 113 RawClass* SnapshotReader::LookupInternalClass(intptr_t class_header) {
113 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); 114 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header);
114 intptr_t header_value = SerializedHeaderData::decode(class_header);
115 115
116 // If the header is an object Id, lookup singleton VM classes or classes 116 // If the header is an object Id, lookup singleton VM classes or classes
117 // stored in the object store. 117 // stored in the object store.
118 if (header_type == kObjectId) { 118 if (header_type == kObjectId) {
119 intptr_t header_value = SerializedHeaderData::decode(class_header);
119 if (IsSingletonClassId(header_value)) { 120 if (IsSingletonClassId(header_value)) {
120 return Object::GetSingletonClass(header_value); // return the singleton. 121 return Object::GetSingletonClass(header_value); // return the singleton.
121 } else if (IsObjectStoreClassId(header_value)) { 122 } else if (IsObjectStoreClassId(header_value)) {
122 return object_store()->GetClass(header_value); 123 return object_store()->GetClass(header_value);
123 } 124 }
124 } 125 }
125 return Class::null(); 126 return Class::null();
126 } 127 }
127 128
128 129
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 163
163 ASSERT(object_id >= kMaxPredefinedObjectIds); 164 ASSERT(object_id >= kMaxPredefinedObjectIds);
164 intptr_t index = object_id - kMaxPredefinedObjectIds; 165 intptr_t index = object_id - kMaxPredefinedObjectIds;
165 ASSERT(index < backward_references_.length()); 166 ASSERT(index < backward_references_.length());
166 return backward_references_[index]->raw(); 167 return backward_references_[index]->raw();
167 } 168 }
168 169
169 170
170 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) { 171 RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) {
171 // Read the class header information and lookup the class. 172 // Read the class header information and lookup the class.
172 intptr_t class_header = Read<intptr_t>(); 173 intptr_t class_header = ReadIntptrValue();
173 intptr_t tags = Read<intptr_t>(); 174 intptr_t tags = ReadIntptrValue();
174 Class& cls = Class::Handle(); 175 Class& cls = Class::Handle();
175 Object& obj = Object::Handle(); 176 Object& obj = Object::Handle();
176 if (SerializedHeaderData::decode(class_header) == kInstanceId) { 177 if (SerializedHeaderData::decode(class_header) == kInstanceId) {
177 // Object is regular dart instance. 178 // Object is regular dart instance.
178 Instance& result = Instance::ZoneHandle(); 179 Instance& result = Instance::ZoneHandle();
179 AddBackwardReference(object_id, &result); 180 AddBackwardReference(object_id, &result);
180 181
181 cls ^= ReadObject(); 182 cls ^= ReadObject();
182 ASSERT(!cls.IsNull()); 183 ASSERT(!cls.IsNull());
183 intptr_t instance_size = cls.instance_size(); 184 intptr_t instance_size = cls.instance_size();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // - Object that is seen for the first time (inlined as follows): 250 // - Object that is seen for the first time (inlined as follows):
250 // (object size in multiples of kObjectAlignment | 0x1) 251 // (object size in multiples of kObjectAlignment | 0x1)
251 // serialized fields of the object 252 // serialized fields of the object
252 // ...... 253 // ......
253 254
254 NoGCScope no_gc; 255 NoGCScope no_gc;
255 // writing a snap shot. 256 // writing a snap shot.
256 257
257 // First check if it is a Smi (i.e not a heap object). 258 // First check if it is a Smi (i.e not a heap object).
258 if (!rawobj->IsHeapObject()) { 259 if (!rawobj->IsHeapObject()) {
259 Write<RawObject*>(rawobj); 260 Write<int64_t>(reinterpret_cast<int64_t>(rawobj));
260 return; 261 return;
261 } 262 }
262 263
263 // Check if it is a singleton null object which is shared by all isolates. 264 // Check if it is a singleton null object which is shared by all isolates.
264 if (rawobj == Object::null()) { 265 if (rawobj == Object::null()) {
265 WriteIndexedObject(Object::kNullObject); 266 WriteIndexedObject(Object::kNullObject);
266 return; 267 return;
267 } 268 }
268 269
269 // Check if it is a singleton sentinel object which is shared by all isolates. 270 // Check if it is a singleton sentinel object which is shared by all isolates.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 object_store->VisitObjectPointers(&visitor); 331 object_store->VisitObjectPointers(&visitor);
331 332
332 // Finalize the snapshot buffer. 333 // Finalize the snapshot buffer.
333 FinalizeBuffer(); 334 FinalizeBuffer();
334 } 335 }
335 336
336 337
337 intptr_t SnapshotWriter::MarkObject(RawObject* raw, RawClass* cls) { 338 intptr_t SnapshotWriter::MarkObject(RawObject* raw, RawClass* cls) {
338 NoGCScope no_gc; 339 NoGCScope no_gc;
339 intptr_t object_id = forward_list_.length() + kMaxPredefinedObjectIds; 340 intptr_t object_id = forward_list_.length() + kMaxPredefinedObjectIds;
341 ASSERT(object_id <= kMaxObjectId);
340 uword value = 0; 342 uword value = 0;
341 value = SerializedHeaderTag::update(kObjectId, value); 343 value = SerializedHeaderTag::update(kObjectId, value);
342 value = SerializedHeaderData::update(object_id, value); 344 value = SerializedHeaderData::update(object_id, value);
343 raw->ptr()->class_ = reinterpret_cast<RawClass*>(value); 345 raw->ptr()->class_ = reinterpret_cast<RawClass*>(value);
344 ForwardObjectNode* node = new ForwardObjectNode(raw, cls); 346 ForwardObjectNode* node = new ForwardObjectNode(raw, cls);
345 ASSERT(node != NULL); 347 ASSERT(node != NULL);
346 forward_list_.Add(node); 348 forward_list_.Add(node);
347 return object_id; 349 return object_id;
348 } 350 }
349 351
(...skipping 21 matching lines...) Expand all
371 // TODO(5411462): figure out what we need to do if an object with native 373 // TODO(5411462): figure out what we need to do if an object with native
372 // fields is serialized (throw exception or serialize a null object). 374 // fields is serialized (throw exception or serialize a null object).
373 ASSERT(cls->ptr()->num_native_fields_ == 0); 375 ASSERT(cls->ptr()->num_native_fields_ == 0);
374 intptr_t instance_size = cls->ptr()->instance_size_; 376 intptr_t instance_size = cls->ptr()->instance_size_;
375 ASSERT(instance_size != 0); 377 ASSERT(instance_size != 0);
376 378
377 // Write out the serialization header value for this object. 379 // Write out the serialization header value for this object.
378 WriteSerializationMarker(kInlined, object_id); 380 WriteSerializationMarker(kInlined, object_id);
379 381
380 // Indicate this is an instance object. 382 // Indicate this is an instance object.
381 Write<intptr_t>(SerializedHeaderData::encode(kInstanceId)); 383 WriteIntptrValue(SerializedHeaderData::encode(kInstanceId));
382 384
383 // Write out the tags. 385 // Write out the tags.
384 Write<intptr_t>(raw->ptr()->tags_); 386 WriteIntptrValue(raw->ptr()->tags_);
385 387
386 // Write out the class information for this object. 388 // Write out the class information for this object.
387 WriteObject(cls); 389 WriteObject(cls);
388 390
389 // Write out all the fields for the object. 391 // Write out all the fields for the object.
390 intptr_t offset = Object::InstanceSize(); 392 intptr_t offset = Object::InstanceSize();
391 while (offset < instance_size) { 393 while (offset < instance_size) {
392 WriteObject(*reinterpret_cast<RawObject**>( 394 WriteObject(*reinterpret_cast<RawObject**>(
393 reinterpret_cast<uword>(raw->ptr()) + offset)); 395 reinterpret_cast<uword>(raw->ptr()) + offset));
394 offset += kWordSize; 396 offset += kWordSize;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 445
444 446
445 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { 447 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
446 for (RawObject** current = first; current <= last; current++) { 448 for (RawObject** current = first; current <= last; current++) {
447 RawObject* raw_obj = *current; 449 RawObject* raw_obj = *current;
448 writer_->WriteObject(raw_obj); 450 writer_->WriteObject(raw_obj);
449 } 451 }
450 } 452 }
451 453
452 } // namespace dart 454 } // namespace dart
OLDNEW
« vm/snapshot.h ('K') | « vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698