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

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

Issue 387993007: 5% smaller snapshots by omitting object ids when possible (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 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 | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot.h » ('j') | 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/bigint_operations.h" 5 #include "vm/bigint_operations.h"
6 #include "vm/dart_api_message.h" 6 #include "vm/dart_api_message.h"
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/snapshot_ids.h" 8 #include "vm/snapshot_ids.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 #include "vm/unicode.h" 10 #include "vm/unicode.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 object = AllocateDartCObjectString(len); 373 object = AllocateDartCObjectString(len);
374 char* p = object->value.as_string; 374 char* p = object->value.as_string;
375 memmove(p, str->ptr()->data(), len); 375 memmove(p, str->ptr()->data(), len);
376 p[len] = '\0'; 376 p[len] = '\0';
377 ASSERT(vm_symbol_references_[symbol_id] == NULL); 377 ASSERT(vm_symbol_references_[symbol_id] == NULL);
378 vm_symbol_references_[symbol_id] = object; 378 vm_symbol_references_[symbol_id] = object;
379 return object; 379 return object;
380 } 380 }
381 381
382 382
383 intptr_t ApiMessageReader::NextAvailableObjectId() const {
384 return backward_references_.length() + kMaxPredefinedObjectIds;
385 }
386
387
383 Dart_CObject* ApiMessageReader::ReadObjectRef() { 388 Dart_CObject* ApiMessageReader::ReadObjectRef() {
384 int64_t value64 = Read<int64_t>(); 389 int64_t value64 = Read<int64_t>();
385 if ((value64 & kSmiTagMask) == 0) { 390 if ((value64 & kSmiTagMask) == 0) {
386 int64_t untagged_value = value64 >> kSmiTagShift; 391 int64_t untagged_value = value64 >> kSmiTagShift;
387 if ((kMinInt32 <= untagged_value) && (untagged_value <= kMaxInt32)) { 392 if ((kMinInt32 <= untagged_value) && (untagged_value <= kMaxInt32)) {
388 return AllocateDartCObjectInt32(static_cast<int32_t>(untagged_value)); 393 return AllocateDartCObjectInt32(static_cast<int32_t>(untagged_value));
389 } else { 394 } else {
390 return AllocateDartCObjectInt64(untagged_value); 395 return AllocateDartCObjectInt64(untagged_value);
391 } 396 }
392 } 397 }
393 ASSERT((value64 <= kIntptrMax) && (value64 >= kIntptrMin)); 398 ASSERT((value64 <= kIntptrMax) && (value64 >= kIntptrMin));
394 intptr_t value = static_cast<intptr_t>(value64); 399 intptr_t value = static_cast<intptr_t>(value64);
395 if (IsVMIsolateObject(value)) { 400 if (IsVMIsolateObject(value)) {
396 return ReadVMIsolateObject(value); 401 return ReadVMIsolateObject(value);
397 } 402 }
398 if (SerializedHeaderTag::decode(value) == kObjectId) { 403 if (SerializedHeaderTag::decode(value) == kObjectId) {
399 return ReadIndexedObject(SerializedHeaderData::decode(value)); 404 return ReadIndexedObject(SerializedHeaderData::decode(value));
400 } 405 }
401 ASSERT(SerializedHeaderTag::decode(value) == kInlined); 406 ASSERT(SerializedHeaderTag::decode(value) == kInlined);
402 // Read the class header information and lookup the class. 407 // Read the class header information and lookup the class.
403 intptr_t class_header = ReadIntptrValue(); 408 intptr_t class_header = ReadIntptrValue();
404 409
410 intptr_t object_id = SerializedHeaderData::decode(value);
411 if (object_id == kOmittedObjectId) {
412 object_id = NextAvailableObjectId();
413 }
414
405 // Reading of regular dart instances has limited support in order to 415 // Reading of regular dart instances has limited support in order to
406 // read typed data views. 416 // read typed data views.
407 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { 417 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) {
408 intptr_t object_id = SerializedHeaderData::decode(value);
409 Dart_CObject_Internal* object = 418 Dart_CObject_Internal* object =
410 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); 419 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized);
411 AddBackRef(object_id, object, kIsNotDeserialized); 420 AddBackRef(object_id, object, kIsNotDeserialized);
412 // Read class of object. 421 // Read class of object.
413 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); 422 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl());
414 ASSERT(object->cls->type == 423 ASSERT(object->cls->type ==
415 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kClass)); 424 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kClass));
416 return object; 425 return object;
417 } 426 }
418 ASSERT((class_header & kSmiTagMask) != 0); 427 ASSERT((class_header & kSmiTagMask) != 0);
419 intptr_t object_id = SerializedHeaderData::decode(value);
420 intptr_t class_id = LookupInternalClass(class_header); 428 intptr_t class_id = LookupInternalClass(class_header);
421 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { 429 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) {
422 ASSERT(GetBackRef(object_id) == NULL); 430 ASSERT(GetBackRef(object_id) == NULL);
423 intptr_t len = ReadSmiValue(); 431 intptr_t len = ReadSmiValue();
424 Dart_CObject* value = AllocateDartCObjectArray(len); 432 Dart_CObject* value = AllocateDartCObjectArray(len);
425 AddBackRef(object_id, value, kIsNotDeserialized); 433 AddBackRef(object_id, value, kIsNotDeserialized);
426 return value; 434 return value;
427 } 435 }
428 436
429 intptr_t tags = ReadTags(); 437 intptr_t tags = ReadTags();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 } 752 }
745 ASSERT((value64 <= kIntptrMax) && (value64 >= kIntptrMin)); 753 ASSERT((value64 <= kIntptrMax) && (value64 >= kIntptrMin));
746 intptr_t value = static_cast<intptr_t>(value64); 754 intptr_t value = static_cast<intptr_t>(value64);
747 if (IsVMIsolateObject(value)) { 755 if (IsVMIsolateObject(value)) {
748 return ReadVMIsolateObject(value); 756 return ReadVMIsolateObject(value);
749 } 757 }
750 if (SerializedHeaderTag::decode(value) == kObjectId) { 758 if (SerializedHeaderTag::decode(value) == kObjectId) {
751 return ReadIndexedObject(SerializedHeaderData::decode(value)); 759 return ReadIndexedObject(SerializedHeaderData::decode(value));
752 } 760 }
753 ASSERT(SerializedHeaderTag::decode(value) == kInlined); 761 ASSERT(SerializedHeaderTag::decode(value) == kInlined);
754 return ReadInlinedObject(SerializedHeaderData::decode(value)); 762
763 intptr_t object_id = SerializedHeaderData::decode(value);
764 if (object_id == kOmittedObjectId) {
765 object_id = NextAvailableObjectId();
766 }
767 return ReadInlinedObject(object_id);
755 } 768 }
756 769
757 770
758 void ApiMessageReader::AddBackRef(intptr_t id, 771 void ApiMessageReader::AddBackRef(intptr_t id,
759 Dart_CObject* obj, 772 Dart_CObject* obj,
760 DeserializeState state) { 773 DeserializeState state) {
761 intptr_t index = (id - kMaxPredefinedObjectIds); 774 intptr_t index = (id - kMaxPredefinedObjectIds);
762 ASSERT(index == backward_references_.length()); 775 ASSERT(index == backward_references_.length());
763 BackRefNode* node = AllocateBackRefNode(obj, state); 776 BackRefNode* node = AllocateBackRefNode(obj, state);
764 ASSERT(node != NULL); 777 ASSERT(node != NULL);
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (!success) { 1194 if (!success) {
1182 UnmarkAllCObjects(object); 1195 UnmarkAllCObjects(object);
1183 return false; 1196 return false;
1184 } 1197 }
1185 } 1198 }
1186 UnmarkAllCObjects(object); 1199 UnmarkAllCObjects(object);
1187 return true; 1200 return true;
1188 } 1201 }
1189 1202
1190 } // namespace dart 1203 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698