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

Unified Diff: runtime/vm/snapshot.cc

Issue 9407010: Move MessageWriter from snapshot files to dart_api_message files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/snapshot.cc
diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc
index edaaa2b5c12d1a37c9dcc3801e3e2a35448554df..b5b81153e6517e741a4ebe0f119cf8f85e1f5436 100644
--- a/runtime/vm/snapshot.cc
+++ b/runtime/vm/snapshot.cc
@@ -437,219 +437,6 @@ RawObject* SnapshotReader::ReadInlinedObject(intptr_t object_id) {
}
-void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) {
- // Write out the serialization header value for this object.
- WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds);
-
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kArrayClass, 0);
-
- // Write out the length field.
- Write<RawObject*>(Smi::New(field_count));
-
- // Write out the type arguments.
- WriteIndexedObject(Object::kNullObject);
-
- // Write out the individual Smis.
- for (int i = 0; i < field_count; i++) {
- Write<RawObject*>(Integer::New(data[i]));
- }
-
- FinalizeBuffer();
-}
-
-
-void MessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) {
- // Mark the object as serialized by adding the object id to the
- // upper bits of the type field in the Dart_CObject structure. Add
- // an offset for making marking of object id 0 possible.
- ASSERT(!IsCObjectMarked(object));
- intptr_t mark_value = object_id + kDartCObjectMarkOffset;
- object->type = static_cast<Dart_CObject::Type>(
- ((mark_value) << kDartCObjectTypeBits) | object->type);
-}
-
-
-void MessageWriter::UnmarkCObject(Dart_CObject* object) {
- ASSERT(IsCObjectMarked(object));
- object->type = static_cast<Dart_CObject::Type>(
- object->type & kDartCObjectTypeMask);
-}
-
-
-bool MessageWriter::IsCObjectMarked(Dart_CObject* object) {
- return (object->type & kDartCObjectMarkMask) != 0;
-}
-
-
-intptr_t MessageWriter::GetMarkedCObjectMark(Dart_CObject* object) {
- ASSERT(IsCObjectMarked(object));
- intptr_t mark_value = ((object->type & kDartCObjectMarkMask) >> 3);
- // An offset was added to object id for making marking object id 0 possible.
- return mark_value - kDartCObjectMarkOffset;
-}
-
-
-void MessageWriter::UnmarkAllCObjects(Dart_CObject* object) {
- if (!IsCObjectMarked(object)) return;
- UnmarkCObject(object);
- if (object->type == Dart_CObject::kArray) {
- for (int i = 0; i < object->value.as_array.length; i++) {
- Dart_CObject* element = object->value.as_array.values[i];
- UnmarkAllCObjects(element);
- }
- }
-}
-
-
-void MessageWriter::WriteSmi(int64_t value) {
- ASSERT(Smi::IsValid64(value));
- Write<RawObject*>(Smi::New(value));
-}
-
-
-void MessageWriter::WriteMint(Dart_CObject* object, int64_t value) {
- ASSERT(!Smi::IsValid64(value));
- // Write out the serialization header value for mint object.
- WriteInlinedHeader(object);
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kMintClass, 0);
- // Write the 64-bit value.
- Write<int64_t>(value);
-}
-
-
-void MessageWriter::WriteInt32(Dart_CObject* object) {
- int64_t value = object->value.as_int32;
- if (Smi::IsValid64(value)) {
- WriteSmi(value);
- } else {
- WriteMint(object, value);
- }
-}
-
-
-void MessageWriter::WriteInt64(Dart_CObject* object) {
- int64_t value = object->value.as_int64;
- if (Smi::IsValid64(value)) {
- WriteSmi(value);
- } else {
- WriteMint(object, value);
- }
-}
-
-
-void MessageWriter::WriteInlinedHeader(Dart_CObject* object) {
- // Write out the serialization header value for this object.
- WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id_);
- // Mark object with its object id.
- MarkCObject(object, object_id_);
- // Advance object id.
- object_id_++;
-}
-
-
-void MessageWriter::WriteCObject(Dart_CObject* object) {
- if (IsCObjectMarked(object)) {
- intptr_t object_id = GetMarkedCObjectMark(object);
- WriteIndexedObject(kMaxPredefinedObjectIds + object_id);
- return;
- }
-
- switch (object->type) {
- case Dart_CObject::kNull:
- WriteIndexedObject(Object::kNullObject);
- break;
- case Dart_CObject::kBool:
- if (object->value.as_bool) {
- WriteIndexedObject(ObjectStore::kTrueValue);
- } else {
- WriteIndexedObject(ObjectStore::kFalseValue);
- }
- break;
- case Dart_CObject::kInt32:
- WriteInt32(object);
- break;
- case Dart_CObject::kInt64:
- WriteInt64(object);
- break;
- case Dart_CObject::kBigint: {
- // Write out the serialization header value for this object.
- WriteInlinedHeader(object);
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kBigintClass, 0);
- // Write hex string length and content
- char* hex_string = object->value.as_bigint;
- intptr_t len = strlen(hex_string);
- WriteIntptrValue(len);
- for (intptr_t i = 0; i < len; i++) {
- Write<uint8_t>(hex_string[i]);
- }
- break;
- }
- case Dart_CObject::kDouble:
- // Write out the serialization header value for this object.
- WriteInlinedHeader(object);
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kDoubleClass, 0);
- // Write double value.
- Write<double>(object->value.as_double);
- break;
- case Dart_CObject::kString: {
- // Write out the serialization header value for this object.
- WriteInlinedHeader(object);
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kOneByteStringClass, 0);
- // Write string length, hash and content
- char* str = object->value.as_string;
- intptr_t len = strlen(str);
- WriteSmi(len);
- WriteSmi(0); // TODO(sgjesse): Hash - not written.
- for (intptr_t i = 0; i < len; i++) {
- Write<uint8_t>(str[i]);
- }
- break;
- }
- case Dart_CObject::kArray: {
- // Write out the serialization header value for this object.
- WriteInlinedHeader(object);
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kArrayClass, 0);
- WriteSmi(object->value.as_array.length);
- // Write out the type arguments.
- WriteIndexedObject(Object::kNullObject);
- // Write out array elements.
- for (int i = 0; i < object->value.as_array.length; i++) {
- WriteCObject(object->value.as_array.values[i]);
- }
- break;
- }
- case Dart_CObject::kByteArray: {
- // Write out the serialization header value for this object.
- WriteInlinedHeader(object);
- // Write out the class and tags information.
- WriteObjectHeader(ObjectStore::kInternalByteArrayClass, 0);
- uint8_t* bytes = object->value.as_byte_array.values;
- intptr_t len = object->value.as_byte_array.length;
- WriteSmi(len);
- for (intptr_t i = 0; i < len; i++) {
- Write<uint8_t>(bytes[i]);
- }
- break;
- }
- default:
- UNREACHABLE();
- }
-}
-
-
-void MessageWriter::WriteCMessage(Dart_CObject* object) {
- WriteCObject(object);
- UnmarkAllCObjects(object);
- FinalizeBuffer();
-}
-
-
void SnapshotWriter::WriteObject(RawObject* rawobj) {
// An object is written in one of the following ways:
// - Smi: the Smi value is written as is (last bit is not tagged).
« no previous file with comments | « runtime/vm/snapshot.h ('k') | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698