| OLD | NEW |
| 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/dart_api_message.h" | 5 #include "vm/dart_api_message.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject::Type type) { | 56 Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject::Type type) { |
| 57 Dart_CObject* value = | 57 Dart_CObject* value = |
| 58 reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject))); | 58 reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject))); |
| 59 ASSERT(value != NULL); | 59 ASSERT(value != NULL); |
| 60 value->type = type; | 60 value->type = type; |
| 61 return value; | 61 return value; |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 Dart_CObject* ApiMessageReader::AllocateDartCObjectUnsupported() { |
| 66 return AllocateDartCObject(Dart_CObject::kUnsupported); |
| 67 } |
| 68 |
| 69 |
| 65 Dart_CObject* ApiMessageReader::AllocateDartCObjectNull() { | 70 Dart_CObject* ApiMessageReader::AllocateDartCObjectNull() { |
| 66 return AllocateDartCObject(Dart_CObject::kNull); | 71 return AllocateDartCObject(Dart_CObject::kNull); |
| 67 } | 72 } |
| 68 | 73 |
| 69 | 74 |
| 70 Dart_CObject* ApiMessageReader::AllocateDartCObjectBool(bool val) { | 75 Dart_CObject* ApiMessageReader::AllocateDartCObjectBool(bool val) { |
| 71 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kBool); | 76 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kBool); |
| 72 value->value.as_bool = val; | 77 value->value.as_bool = val; |
| 73 return value; | 78 return value; |
| 74 } | 79 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 168 |
| 164 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 169 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
| 165 // Read the class header information and lookup the class. | 170 // Read the class header information and lookup the class. |
| 166 intptr_t class_header = ReadIntptrValue(); | 171 intptr_t class_header = ReadIntptrValue(); |
| 167 intptr_t tags = ReadIntptrValue(); | 172 intptr_t tags = ReadIntptrValue(); |
| 168 USE(tags); | 173 USE(tags); |
| 169 intptr_t class_id; | 174 intptr_t class_id; |
| 170 | 175 |
| 171 // Reading of regular dart instances is not supported. | 176 // Reading of regular dart instances is not supported. |
| 172 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | 177 if (SerializedHeaderData::decode(class_header) == kInstanceId) { |
| 173 return NULL; | 178 return AllocateDartCObjectUnsupported(); |
| 174 } | 179 } |
| 175 | 180 |
| 176 ASSERT((class_header & kSmiTagMask) != 0); | 181 ASSERT((class_header & kSmiTagMask) != 0); |
| 177 class_id = LookupInternalClass(class_header); | 182 class_id = LookupInternalClass(class_header); |
| 178 switch (class_id) { | 183 switch (class_id) { |
| 179 case Object::kClassClass: { | 184 case Object::kClassClass: { |
| 180 return NULL; | 185 return AllocateDartCObjectUnsupported(); |
| 181 } | 186 } |
| 182 case Object::kTypeArgumentsClass: { | 187 case Object::kTypeArgumentsClass: { |
| 183 // TODO(sjesse): Remove this when message serialization format is | 188 // TODO(sjesse): Remove this when message serialization format is |
| 184 // updated (currently length is leaked). | 189 // updated (currently length is leaked). |
| 185 Dart_CObject* value = &type_arguments_marker; | 190 Dart_CObject* value = &type_arguments_marker; |
| 186 AddBackwardReference(object_id, value); | 191 AddBackwardReference(object_id, value); |
| 187 Dart_CObject* length = ReadObject(); | 192 Dart_CObject* length = ReadObject(); |
| 188 ASSERT(length->type == Dart_CObject::kInt32); | 193 ASSERT(length->type == Dart_CObject::kInt32); |
| 189 for (int i = 0; i < length->value.as_int32; i++) { | 194 for (int i = 0; i < length->value.as_int32; i++) { |
| 190 Dart_CObject* type = ReadObject(); | 195 Dart_CObject* type = ReadObject(); |
| 191 if (type != &dynamic_type_marker) { | 196 if (type != &dynamic_type_marker) { |
| 192 return NULL; | 197 return AllocateDartCObjectUnsupported(); |
| 193 } | 198 } |
| 194 } | 199 } |
| 195 return value; | 200 return value; |
| 196 } | 201 } |
| 197 case Object::kTypeParameterClass: { | 202 case Object::kTypeParameterClass: { |
| 198 // TODO(sgjesse): Fix this workaround ignoring the type parameter. | 203 // TODO(sgjesse): Fix this workaround ignoring the type parameter. |
| 199 Dart_CObject* value = &dynamic_type_marker; | 204 Dart_CObject* value = &dynamic_type_marker; |
| 200 AddBackwardReference(object_id, value); | 205 AddBackwardReference(object_id, value); |
| 201 intptr_t index = ReadIntptrValue(); | 206 intptr_t index = ReadIntptrValue(); |
| 202 USE(index); | 207 USE(index); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 214 case ObjectStore::kArrayClass: { | 219 case ObjectStore::kArrayClass: { |
| 215 intptr_t len = ReadSmiValue(); | 220 intptr_t len = ReadSmiValue(); |
| 216 Dart_CObject* value = AllocateDartCObjectArray(len); | 221 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 217 AddBackwardReference(object_id, value); | 222 AddBackwardReference(object_id, value); |
| 218 // Skip type arguments. | 223 // Skip type arguments. |
| 219 // TODO(sjesse): Remove this when message serialization format is | 224 // TODO(sjesse): Remove this when message serialization format is |
| 220 // updated (currently type_arguments is leaked). | 225 // updated (currently type_arguments is leaked). |
| 221 Dart_CObject* type_arguments = ReadObject(); | 226 Dart_CObject* type_arguments = ReadObject(); |
| 222 if (type_arguments != &type_arguments_marker && | 227 if (type_arguments != &type_arguments_marker && |
| 223 type_arguments->type != Dart_CObject::kNull) { | 228 type_arguments->type != Dart_CObject::kNull) { |
| 224 return NULL; | 229 return AllocateDartCObjectUnsupported(); |
| 225 } | 230 } |
| 226 for (int i = 0; i < len; i++) { | 231 for (int i = 0; i < len; i++) { |
| 227 value->value.as_array.values[i] = ReadObject(); | 232 value->value.as_array.values[i] = ReadObject(); |
| 228 } | 233 } |
| 229 return value; | 234 return value; |
| 230 } | 235 } |
| 231 case ObjectStore::kMintClass: { | 236 case ObjectStore::kMintClass: { |
| 232 int64_t value = Read<int64_t>(); | 237 int64_t value = Read<int64_t>(); |
| 233 Dart_CObject* object; | 238 Dart_CObject* object; |
| 234 if (kMinInt32 <= value && value <= kMaxInt32) { | 239 if (kMinInt32 <= value && value <= kMaxInt32) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 265 AddBackwardReference(object_id, object); | 270 AddBackwardReference(object_id, object); |
| 266 char* p = object->value.as_string; | 271 char* p = object->value.as_string; |
| 267 for (intptr_t i = 0; i < len; i++) { | 272 for (intptr_t i = 0; i < len; i++) { |
| 268 p[i] = Read<uint8_t>(); | 273 p[i] = Read<uint8_t>(); |
| 269 } | 274 } |
| 270 p[len] = '\0'; | 275 p[len] = '\0'; |
| 271 return object; | 276 return object; |
| 272 } | 277 } |
| 273 case ObjectStore::kTwoByteStringClass: | 278 case ObjectStore::kTwoByteStringClass: |
| 274 // Two byte strings not supported. | 279 // Two byte strings not supported. |
| 275 return NULL; | 280 return AllocateDartCObjectUnsupported(); |
| 276 case ObjectStore::kFourByteStringClass: | 281 case ObjectStore::kFourByteStringClass: |
| 277 // Four byte strings not supported. | 282 // Four byte strings not supported. |
| 278 return NULL; | 283 return AllocateDartCObjectUnsupported(); |
| 279 case ObjectStore::kUint8ArrayClass: { | 284 case ObjectStore::kUint8ArrayClass: { |
| 280 intptr_t len = ReadSmiValue(); | 285 intptr_t len = ReadSmiValue(); |
| 281 Dart_CObject* object = AllocateDartCObjectUint8Array(len); | 286 Dart_CObject* object = AllocateDartCObjectUint8Array(len); |
| 282 AddBackwardReference(object_id, object); | 287 AddBackwardReference(object_id, object); |
| 283 if (len > 0) { | 288 if (len > 0) { |
| 284 uint8_t* p = object->value.as_byte_array.values; | 289 uint8_t* p = object->value.as_byte_array.values; |
| 285 for (intptr_t i = 0; i < len; i++) { | 290 for (intptr_t i = 0; i < len; i++) { |
| 286 p[i] = Read<uint8_t>(); | 291 p[i] = Read<uint8_t>(); |
| 287 } | 292 } |
| 288 } | 293 } |
| 289 return object; | 294 return object; |
| 290 } | 295 } |
| 291 default: | 296 default: |
| 292 // Everything else not supported. | 297 // Everything else not supported. |
| 293 return NULL; | 298 return AllocateDartCObjectUnsupported(); |
| 294 } | 299 } |
| 295 } | 300 } |
| 296 | 301 |
| 297 | 302 |
| 298 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { | 303 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { |
| 299 if (object_id == Object::kNullObject) { | 304 if (object_id == Object::kNullObject) { |
| 300 return AllocateDartCObjectNull(); | 305 return AllocateDartCObjectNull(); |
| 301 } else if (object_id == ObjectStore::kTrueValue) { | 306 } |
| 307 if (object_id == ObjectStore::kTrueValue) { |
| 302 return AllocateDartCObjectBool(true); | 308 return AllocateDartCObjectBool(true); |
| 303 } else if (object_id == ObjectStore::kFalseValue) { | 309 } |
| 310 if (object_id == ObjectStore::kFalseValue) { |
| 304 return AllocateDartCObjectBool(false); | 311 return AllocateDartCObjectBool(false); |
| 305 } else if (object_id == ObjectStore::kDynamicType || | 312 } |
| 306 object_id == ObjectStore::kDoubleInterface || | 313 if (object_id == ObjectStore::kDynamicType || |
| 307 object_id == ObjectStore::kIntInterface || | 314 object_id == ObjectStore::kDoubleInterface || |
| 308 object_id == ObjectStore::kBoolInterface || | 315 object_id == ObjectStore::kIntInterface || |
| 309 object_id == ObjectStore::kStringInterface) { | 316 object_id == ObjectStore::kBoolInterface || |
| 317 object_id == ObjectStore::kStringInterface) { |
| 310 // Always return dynamic type (this is only a marker). | 318 // Always return dynamic type (this is only a marker). |
| 311 return &dynamic_type_marker; | 319 return &dynamic_type_marker; |
| 312 } else { | |
| 313 intptr_t index = object_id - kMaxPredefinedObjectIds; | |
| 314 ASSERT((0 <= index) && (index < backward_references_.length())); | |
| 315 ASSERT(backward_references_[index] != NULL); | |
| 316 return backward_references_[index]; | |
| 317 } | 320 } |
| 318 return NULL; | 321 intptr_t index = object_id - kMaxPredefinedObjectIds; |
| 322 ASSERT((0 <= index) && (index < backward_references_.length())); |
| 323 ASSERT(backward_references_[index] != NULL); |
| 324 return backward_references_[index]; |
| 319 } | 325 } |
| 320 | 326 |
| 321 | 327 |
| 322 Dart_CObject* ApiMessageReader::ReadObjectImpl(intptr_t header) { | 328 Dart_CObject* ApiMessageReader::ReadObjectImpl(intptr_t header) { |
| 323 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); | 329 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); |
| 324 intptr_t header_value = SerializedHeaderData::decode(header); | 330 intptr_t header_value = SerializedHeaderData::decode(header); |
| 325 | 331 |
| 326 if (header_type == kObjectId) { | 332 if (header_type == kObjectId) { |
| 327 return ReadIndexedObject(header_value); | 333 return ReadIndexedObject(header_value); |
| 328 } | 334 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 563 } |
| 558 | 564 |
| 559 | 565 |
| 560 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { | 566 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { |
| 561 WriteCObject(object); | 567 WriteCObject(object); |
| 562 UnmarkAllCObjects(object); | 568 UnmarkAllCObjects(object); |
| 563 FinalizeBuffer(); | 569 FinalizeBuffer(); |
| 564 } | 570 } |
| 565 | 571 |
| 566 } // namespace dart | 572 } // namespace dart |
| OLD | NEW |