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

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

Issue 9104041: Added API Dart_PostCMessage for posting a Dart_CMessage structure (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added new API Dart_PostCMessage Created 8 years, 10 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
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/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/heap.h" 10 #include "vm/heap.h"
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 694
695 // Write out the individual Smis. 695 // Write out the individual Smis.
696 for (int i = 0; i < field_count; i++) { 696 for (int i = 0; i < field_count; i++) {
697 Write<RawObject*>(Integer::New(data[i])); 697 Write<RawObject*>(Integer::New(data[i]));
698 } 698 }
699 699
700 FinalizeBuffer(); 700 FinalizeBuffer();
701 } 701 }
702 702
703 703
704 void MessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) {
705 // Mark the object as serialized by adding the object id to the
706 // upper bits of the type field in the Dart_CObject structure. Add
707 // an offset for making marking of object id 0 possible.
708 ASSERT(!IsCObjectMarked(object));
709 intptr_t mark_value = object_id + kDartCObjectMarkOffset;
710 object->type = static_cast<Dart_CObject::Type>(
711 ((mark_value) << kDartCObjectTypeBits) | object->type);
712 }
713
714
715 void MessageWriter::UnmarkCObject(Dart_CObject* object) {
716 ASSERT(IsCObjectMarked(object));
717 object->type = static_cast<Dart_CObject::Type>(
718 object->type & kDartCObjectTypeMask);
719 }
720
721
722 bool MessageWriter::IsCObjectMarked(Dart_CObject* object) {
723 return (object->type & kDartCObjectMarkMask) != 0;
724 }
725
726
727 intptr_t MessageWriter::GetMarkedCObjectMark(Dart_CObject* object) {
728 ASSERT(IsCObjectMarked(object));
729 intptr_t mark_value = ((object->type & kDartCObjectMarkMask) >> 3);
730 // An offset was added to object id for making marking object id 0 possible.
731 return mark_value - kDartCObjectMarkOffset;
732 }
733
734
735 void MessageWriter::UnmarkAllCObjects(Dart_CObject* object) {
736 if (!IsCObjectMarked(object)) return;
737 UnmarkCObject(object);
738 if (object->type == Dart_CObject::kArray) {
739 for (int i = 0; i < object->value.as_array.length; i++) {
740 Dart_CObject* element = object->value.as_array.values[i];
741 UnmarkAllCObjects(element);
742 }
743 }
744 }
745
746
747 void MessageWriter::WriteSmi(int32_t value) {
748 Write<RawObject*>(Smi::New(value));
749 }
750
751
752 void MessageWriter::WriteInlinedHeader(Dart_CObject* object) {
753 // Write out the serialization header value for this object.
754 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id_);
755 // Mark object with its object id.
756 MarkCObject(object, object_id_);
757 // Advance object id.
758 object_id_++;
759 }
760
761
762 void MessageWriter::WriteCObject(Dart_CObject* object) {
763 if (IsCObjectMarked(object)) {
764 intptr_t object_id = GetMarkedCObjectMark(object);
765 WriteIndexedObject(kMaxPredefinedObjectIds + object_id);
766 return;
767 }
768
769 switch (object->type) {
770 case Dart_CObject::kNull:
771 WriteIndexedObject(Object::kNullObject);
772 break;
773 case Dart_CObject::kBool:
774 if (object->value.as_bool) {
775 WriteIndexedObject(ObjectStore::kTrueValue);
776 } else {
777 WriteIndexedObject(ObjectStore::kFalseValue);
778 }
779 break;
780 case Dart_CObject::kInt32: {
781 WriteSmi(object->value.as_int32);
782 break;
783 }
784 case Dart_CObject::kDouble:
785 // Write out the serialization header value for this object.
786 WriteInlinedHeader(object);
787 // Write out the class and tags information.
788 WriteObjectHeader(ObjectStore::kDoubleClass, 0);
789 // Write double value.
790 Write<double>(object->value.as_double);
791 break;
792 case Dart_CObject::kString: {
793 // Write out the serialization header value for this object.
794 WriteInlinedHeader(object);
795 // Write out the class and tags information.
796 WriteObjectHeader(ObjectStore::kOneByteStringClass, 0);
797 // Write string length, hash and content
798 char* str = object->value.as_string;
799 intptr_t len = strlen(str);
800 WriteSmi(len);
801 WriteSmi(0); // TODO(sgjesse): Hash - not written.
802 for (intptr_t i = 0; i < len; i++) {
803 Write<uint8_t>(str[i]);
804 }
805 break;
806 }
807 case Dart_CObject::kArray: {
808 // Write out the serialization header value for this object.
809 WriteInlinedHeader(object);
810 // Write out the class and tags information.
811 WriteObjectHeader(ObjectStore::kArrayClass, 0);
812 WriteSmi(object->value.as_array.length);
813 // Write out the type arguments.
814 WriteIndexedObject(Object::kNullObject);
815 // Write out array elements.
816 for (int i = 0; i < object->value.as_array.length; i++) {
817 WriteCObject(object->value.as_array.values[i]);
818 }
819 break;
820 }
821 default:
822 UNREACHABLE();
823 }
824 }
825
826
827 void MessageWriter::WriteCMessage(Dart_CObject* object) {
828 WriteCObject(object);
829 UnmarkAllCObjects(object);
830 FinalizeBuffer();
831 }
832
833
704 void SnapshotWriter::WriteObject(RawObject* rawobj) { 834 void SnapshotWriter::WriteObject(RawObject* rawobj) {
705 // An object is written in one of the following ways: 835 // An object is written in one of the following ways:
706 // - Smi: the Smi value is written as is (last bit is not tagged). 836 // - Smi: the Smi value is written as is (last bit is not tagged).
707 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) 837 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3)
708 // - Object that has already been written: (negative id in stream | 0x3) 838 // - Object that has already been written: (negative id in stream | 0x3)
709 // - Object that is seen for the first time (inlined as follows): 839 // - Object that is seen for the first time (inlined as follows):
710 // (object size in multiples of kObjectAlignment | 0x1) 840 // (object size in multiples of kObjectAlignment | 0x1)
711 // serialized fields of the object 841 // serialized fields of the object
712 // ...... 842 // ......
713 843
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 1034
905 1035
906 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { 1036 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
907 for (RawObject** current = first; current <= last; current++) { 1037 for (RawObject** current = first; current <= last; current++) {
908 RawObject* raw_obj = *current; 1038 RawObject* raw_obj = *current;
909 writer_->WriteObject(raw_obj); 1039 writer_->WriteObject(raw_obj);
910 } 1040 }
911 } 1041 }
912 1042
913 } // namespace dart 1043 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698