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

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

Issue 10444059: When generate snapshot use tags_ instead of class_ to store object ids. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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/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) 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/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 516 }
517 517
518 // Check if it is a singleton boolean false value. 518 // Check if it is a singleton boolean false value.
519 if (rawobj == object_store()->false_value()) { 519 if (rawobj == object_store()->false_value()) {
520 WriteIndexedObject(ObjectStore::kFalseValue); 520 WriteIndexedObject(ObjectStore::kFalseValue);
521 return; 521 return;
522 } 522 }
523 523
524 // Check if it is a code object in that case just write a Null object 524 // Check if it is a code object in that case just write a Null object
525 // as we do not want code objects in the snapshot. 525 // as we do not want code objects in the snapshot.
526 if (rawobj->ptr()->class_ == Object::code_class()) { 526 if (RawObject::ClassTag::decode(GetObjectTags(rawobj)) == kCode) {
527 WriteIndexedObject(Object::kNullObject); 527 WriteIndexedObject(Object::kNullObject);
528 return; 528 return;
529 } 529 }
530 530
531 // Check if classes are not being serialized and it is preinitialized type. 531 // Check if classes are not being serialized and it is preinitialized type.
532 if (kind_ != Snapshot::kFull) { 532 if (kind_ != Snapshot::kFull) {
533 RawType* raw_type = reinterpret_cast<RawType*>(rawobj); 533 RawType* raw_type = reinterpret_cast<RawType*>(rawobj);
534 index = object_store()->GetTypeIndex(raw_type); 534 index = object_store()->GetTypeIndex(raw_type);
535 if (index != ObjectStore::kInvalidIndex) { 535 if (index != ObjectStore::kInvalidIndex) {
536 WriteIndexedObject(index); 536 WriteIndexedObject(index);
537 return; 537 return;
538 } 538 }
539 } 539 }
540 540
541 // Now write the object out inline in the stream. 541 // Now write the object out inline in the stream.
542 WriteInlinedObject(rawobj); 542 WriteInlinedObject(rawobj);
543 } 543 }
544 544
545 545
546 void SnapshotWriter::UnmarkAll() { 546 void SnapshotWriter::UnmarkAll() {
547 NoGCScope no_gc; 547 NoGCScope no_gc;
548 for (intptr_t i = 0; i < forward_list_.length(); i++) { 548 for (intptr_t i = 0; i < forward_list_.length(); i++) {
549 RawObject* raw = forward_list_[i]->raw(); 549 RawObject* raw = forward_list_[i]->raw();
550 raw->ptr()->class_ = forward_list_[i]->cls(); // Restore original class. 550 raw->ptr()->tags_ = forward_list_[i]->tags(); // Restore original class.
siva 2012/05/30 00:35:29 Comment should be restore original tags_ (will bec
551 } 551 }
552 } 552 }
553 553
554 554
555 void SnapshotWriter::WriteFullSnapshot() { 555 void SnapshotWriter::WriteFullSnapshot() {
556 ASSERT(kind_ == Snapshot::kFull); 556 ASSERT(kind_ == Snapshot::kFull);
557 Isolate* isolate = Isolate::Current(); 557 Isolate* isolate = Isolate::Current();
558 ASSERT(isolate != NULL); 558 ASSERT(isolate != NULL);
559 ObjectStore* object_store = isolate->object_store(); 559 ObjectStore* object_store = isolate->object_store();
560 ASSERT(object_store != NULL); 560 ASSERT(object_store != NULL);
561 561
562 // Write out all the objects in the object store of the isolate which 562 // Write out all the objects in the object store of the isolate which
563 // is the root set for all dart allocated objects at this point. 563 // is the root set for all dart allocated objects at this point.
564 SnapshotWriterVisitor visitor(this); 564 SnapshotWriterVisitor visitor(this);
565 object_store->VisitObjectPointers(&visitor); 565 object_store->VisitObjectPointers(&visitor);
566 566
567 // Finalize the snapshot buffer. 567 // Finalize the snapshot buffer.
568 FinalizeBuffer(); 568 FinalizeBuffer();
569 } 569 }
570 570
571 571
572 uword SnapshotWriter::GetObjectTags(RawObject* raw) {
573 uword tags = raw->ptr()->tags_;
574 if (SerializedHeaderTag::decode(tags) == kObjectId) {
575 intptr_t id = SerializedHeaderData::decode(tags);
576 return forward_list_[id - kMaxPredefinedObjectIds]->tags();
577 } else {
578 return tags;
579 }
580 }
581
582
572 intptr_t SnapshotWriter::MarkObject(RawObject* raw, RawClass* cls) { 583 intptr_t SnapshotWriter::MarkObject(RawObject* raw, RawClass* cls) {
573 NoGCScope no_gc; 584 NoGCScope no_gc;
574 intptr_t object_id = forward_list_.length() + kMaxPredefinedObjectIds; 585 intptr_t object_id = forward_list_.length() + kMaxPredefinedObjectIds;
575 ASSERT(object_id <= kMaxObjectId); 586 ASSERT(object_id <= kMaxObjectId);
576 uword value = 0; 587 uword value = 0;
577 value = SerializedHeaderTag::update(kObjectId, value); 588 value = SerializedHeaderTag::update(kObjectId, value);
578 value = SerializedHeaderData::update(object_id, value); 589 value = SerializedHeaderData::update(object_id, value);
siva 2012/05/30 00:35:29 The SerializedHeaderTag bits collide with the rese
Vyacheslav Egorov (Google) 2012/05/30 07:48:35 Actually there is one change I did not merge from
579 raw->ptr()->class_ = reinterpret_cast<RawClass*>(value); 590 uword tags = raw->ptr()->tags_;
580 ForwardObjectNode* node = new ForwardObjectNode(raw, cls); 591 raw->ptr()->tags_ = value;
592 ForwardObjectNode* node = new ForwardObjectNode(raw, tags);
581 ASSERT(node != NULL); 593 ASSERT(node != NULL);
582 forward_list_.Add(node); 594 forward_list_.Add(node);
583 return object_id; 595 return object_id;
584 } 596 }
585 597
586 598
587 void SnapshotWriter::WriteInlinedObject(RawObject* raw) { 599 void SnapshotWriter::WriteInlinedObject(RawObject* raw) {
588 NoGCScope no_gc; 600 NoGCScope no_gc;
589 RawClass* cls = raw->ptr()->class_; 601 uword tags = raw->ptr()->tags_;
590 602
591 // Check if object has already been serialized, in that 603 // Check if object has already been serialized, in that
592 // case just write the object id out. 604 // case just write the object id out.
593 if (SerializedHeaderTag::decode(reinterpret_cast<uword>(cls)) == kObjectId) { 605 if (SerializedHeaderTag::decode(tags) == kObjectId) {
594 intptr_t id = SerializedHeaderData::decode(reinterpret_cast<intptr_t>(cls)); 606 intptr_t id = SerializedHeaderData::decode(tags);
595 WriteIndexedObject(id); 607 WriteIndexedObject(id);
596 return; 608 return;
597 } 609 }
598 610
611 RawClass* cls = class_table_->At(RawObject::ClassTag::decode(tags));
612
599 // Object is being serialized, add it to the forward ref list and mark 613 // Object is being serialized, add it to the forward ref list and mark
600 // it so that future references to this object in the snapshot will use 614 // it so that future references to this object in the snapshot will use
601 // an object id, instead of trying to serialize it again. 615 // an object id, instead of trying to serialize it again.
602 intptr_t object_id = MarkObject(raw, cls); 616 intptr_t object_id = MarkObject(raw, cls);
603 617
604 ObjectKind kind = cls->ptr()->instance_kind_; 618 ObjectKind kind = cls->ptr()->instance_kind_;
605 if (kind == Instance::kInstanceKind) { 619 if (kind == Instance::kInstanceKind) {
606 // Object is regular dart instance. 620 // Object is regular dart instance.
607 // TODO(5411462): figure out what we need to do if an object with native 621 // TODO(5411462): figure out what we need to do if an object with native
608 // fields is serialized (throw exception or serialize a null object). 622 // fields is serialized (throw exception or serialize a null object).
609 ASSERT(cls->ptr()->num_native_fields_ == 0); 623 ASSERT(cls->ptr()->num_native_fields_ == 0);
610 intptr_t instance_size = cls->ptr()->instance_size_; 624 intptr_t instance_size = cls->ptr()->instance_size_;
611 ASSERT(instance_size != 0); 625 ASSERT(instance_size != 0);
612 626
613 // Write out the serialization header value for this object. 627 // Write out the serialization header value for this object.
614 WriteSerializationMarker(kInlined, object_id); 628 WriteSerializationMarker(kInlined, object_id);
615 629
616 // Indicate this is an instance object. 630 // Indicate this is an instance object.
617 WriteIntptrValue(SerializedHeaderData::encode(kInstanceId)); 631 WriteIntptrValue(SerializedHeaderData::encode(kInstanceId));
618 632
619 // Write out the tags. 633 // Write out the tags.
620 WriteIntptrValue(raw->ptr()->tags_); 634 WriteIntptrValue(tags);
621 635
622 // Write out the class information for this object. 636 // Write out the class information for this object.
623 WriteObject(cls); 637 WriteObject(cls);
624 638
625 // Write out all the fields for the object. 639 // Write out all the fields for the object.
626 intptr_t offset = Object::InstanceSize(); 640 intptr_t offset = Object::InstanceSize();
627 while (offset < instance_size) { 641 while (offset < instance_size) {
628 WriteObject(*reinterpret_cast<RawObject**>( 642 WriteObject(*reinterpret_cast<RawObject**>(
629 reinterpret_cast<uword>(raw->ptr()) + offset)); 643 reinterpret_cast<uword>(raw->ptr()) + offset));
630 offset += kWordSize; 644 offset += kWordSize;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 693
680 694
681 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { 695 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
682 for (RawObject** current = first; current <= last; current++) { 696 for (RawObject** current = first; current <= last; current++) {
683 RawObject* raw_obj = *current; 697 RawObject* raw_obj = *current;
684 writer_->WriteObject(raw_obj); 698 writer_->WriteObject(raw_obj);
685 } 699 }
686 } 700 }
687 701
688 } // namespace dart 702 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698