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

Side by Side Diff: runtime/vm/snapshot.cc

Issue 1378423002: Support serializing ObjectPool as reference. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « runtime/vm/raw_object_snapshot.cc ('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) 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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bootstrap.h" 8 #include "vm/bootstrap.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 60
61 static bool IsSplitClassId(intptr_t class_id) { 61 static bool IsSplitClassId(intptr_t class_id) {
62 // Return whether this class is serialized in two steps: first a reference, 62 // Return whether this class is serialized in two steps: first a reference,
63 // with sufficient information to allocate a correctly sized object, and then 63 // with sufficient information to allocate a correctly sized object, and then
64 // later inline with complete contents. 64 // later inline with complete contents.
65 return class_id >= kNumPredefinedCids || 65 return class_id >= kNumPredefinedCids ||
66 class_id == kArrayCid || 66 class_id == kArrayCid ||
67 class_id == kImmutableArrayCid || 67 class_id == kImmutableArrayCid ||
68 class_id == kObjectPoolCid ||
68 RawObject::IsImplicitFieldClassId(class_id); 69 RawObject::IsImplicitFieldClassId(class_id);
69 } 70 }
70 71
71 72
72 static intptr_t ClassIdFromObjectId(intptr_t object_id) { 73 static intptr_t ClassIdFromObjectId(intptr_t object_id) {
73 ASSERT(object_id > kClassIdsOffset); 74 ASSERT(object_id > kClassIdsOffset);
74 intptr_t class_id = (object_id - kClassIdsOffset); 75 intptr_t class_id = (object_id - kClassIdsOffset);
75 return class_id; 76 return class_id;
76 } 77 }
77 78
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 // Read the length and allocate an object based on the len. 478 // Read the length and allocate an object based on the len.
478 intptr_t len = ReadSmiValue(); 479 intptr_t len = ReadSmiValue();
479 Array& array = Array::ZoneHandle( 480 Array& array = Array::ZoneHandle(
480 zone(), 481 zone(),
481 (kind_ == Snapshot::kFull) ? 482 (kind_ == Snapshot::kFull) ?
482 NewImmutableArray(len) : ImmutableArray::New(len, HEAP_SPACE(kind_))); 483 NewImmutableArray(len) : ImmutableArray::New(len, HEAP_SPACE(kind_)));
483 AddBackRef(object_id, &array, kIsNotDeserialized); 484 AddBackRef(object_id, &array, kIsNotDeserialized);
484 485
485 return array.raw(); 486 return array.raw();
486 } 487 }
488 if (class_id == kObjectPoolCid) {
489 ASSERT(kind_ == Snapshot::kFull);
490 // Read the length and allocate an object based on the len.
491 intptr_t len = Read<intptr_t>();
492 ObjectPool& pool = ObjectPool::ZoneHandle(zone(),
493 NewObjectPool(len));
494 AddBackRef(object_id, &pool, kIsNotDeserialized);
495
496 return pool.raw();
497 }
487 498
488 // For all other internal VM classes we read the object inline. 499 // For all other internal VM classes we read the object inline.
489 switch (class_id) { 500 switch (class_id) {
490 #define SNAPSHOT_READ(clazz) \ 501 #define SNAPSHOT_READ(clazz) \
491 case clazz::kClassId: { \ 502 case clazz::kClassId: { \
492 pobj_ = clazz::ReadFrom(this, object_id, tags, kind_); \ 503 pobj_ = clazz::ReadFrom(this, object_id, tags, kind_); \
493 break; \ 504 break; \
494 } 505 }
495 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ) 506 CLASS_LIST_NO_OBJECT(SNAPSHOT_READ)
496 #undef SNAPSHOT_READ 507 #undef SNAPSHOT_READ
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 2266
2256 // Write out the class information. 2267 // Write out the class information.
2257 WriteIndexedObject(class_id); 2268 WriteIndexedObject(class_id);
2258 WriteTags(tags); 2269 WriteTags(tags);
2259 2270
2260 // Write out the length field. 2271 // Write out the length field.
2261 Write<RawObject*>(rawarray->ptr()->length_); 2272 Write<RawObject*>(rawarray->ptr()->length_);
2262 2273
2263 return; 2274 return;
2264 } 2275 }
2276 if (class_id == kObjectPoolCid) {
2277 intptr_t tags = GetObjectTags(raw);
2278
2279 // Object is being referenced, add it to the forward ref list and mark
2280 // it so that future references to this object in the snapshot will use
2281 // this object id. Mark it as not having been serialized yet so that we
2282 // will serialize the object when we go through the forward list.
2283 forward_list_->MarkAndAddObject(raw, kIsNotSerialized);
2284
2285 RawObjectPool* rawpool = reinterpret_cast<RawObjectPool*>(raw);
2286
2287 // Write out the serialization header value for this object.
2288 WriteInlinedObjectHeader(kOmittedObjectId);
2289
2290 // Write out the class information.
2291 WriteVMIsolateObject(kObjectPoolCid);
2292 WriteTags(tags);
2293
2294 // Write out the length field.
2295 Write<intptr_t>(rawpool->ptr()->length_);
2296
2297 return;
2298 }
2265 // Add object to the forward ref list and mark it so that future references 2299 // Add object to the forward ref list and mark it so that future references
2266 // to this object in the snapshot will use this object id. Mark it as having 2300 // to this object in the snapshot will use this object id. Mark it as having
2267 // been serialized so that we do not serialize the object when we go through 2301 // been serialized so that we do not serialize the object when we go through
2268 // the forward list. 2302 // the forward list.
2269 forward_list_->MarkAndAddObject(raw, kIsSerialized); 2303 forward_list_->MarkAndAddObject(raw, kIsSerialized);
2270 switch (class_id) { 2304 switch (class_id) {
2271 #define SNAPSHOT_WRITE(clazz) \ 2305 #define SNAPSHOT_WRITE(clazz) \
2272 case clazz::kClassId: { \ 2306 case clazz::kClassId: { \
2273 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \ 2307 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(raw); \
2274 raw_obj->WriteTo(this, kOmittedObjectId, kind_); \ 2308 raw_obj->WriteTo(this, kOmittedObjectId, kind_); \
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
2791 NoSafepointScope no_safepoint; 2825 NoSafepointScope no_safepoint;
2792 WriteObject(obj.raw()); 2826 WriteObject(obj.raw());
2793 UnmarkAll(); 2827 UnmarkAll();
2794 } else { 2828 } else {
2795 ThrowException(exception_type(), exception_msg()); 2829 ThrowException(exception_type(), exception_msg());
2796 } 2830 }
2797 } 2831 }
2798 2832
2799 2833
2800 } // namespace dart 2834 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object_snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698