| 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/snapshot_ids.h" | 7 #include "vm/snapshot_ids.h" |
| 8 #include "vm/symbols.h" | 8 #include "vm/symbols.h" |
| 9 #include "vm/unicode.h" | 9 #include "vm/unicode.h" |
| 10 | 10 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 value->value.as_array.length = length; | 157 value->value.as_array.length = length; |
| 158 if (length > 0) { | 158 if (length > 0) { |
| 159 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 159 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
| 160 } else { | 160 } else { |
| 161 value->value.as_array.values = NULL; | 161 value->value.as_array.values = NULL; |
| 162 } | 162 } |
| 163 return value; | 163 return value; |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal( |
| 168 Dart_CObject_Internal::Type type) { |
| 169 Dart_CObject_Internal* value = |
| 170 reinterpret_cast<Dart_CObject_Internal*>( |
| 171 alloc_(NULL, 0, sizeof(Dart_CObject_Internal))); |
| 172 ASSERT(value != NULL); |
| 173 value->type = static_cast<Dart_CObject::Type>(type); |
| 174 return value; |
| 175 } |
| 176 |
| 177 |
| 178 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectClass() { |
| 179 return AllocateDartCObjectInternal(Dart_CObject_Internal::kClass); |
| 180 } |
| 181 |
| 182 |
| 167 ApiMessageReader::BackRefNode* ApiMessageReader::AllocateBackRefNode( | 183 ApiMessageReader::BackRefNode* ApiMessageReader::AllocateBackRefNode( |
| 168 Dart_CObject* reference, | 184 Dart_CObject* reference, |
| 169 DeserializeState state) { | 185 DeserializeState state) { |
| 170 BackRefNode* value = | 186 BackRefNode* value = |
| 171 reinterpret_cast<BackRefNode*>(alloc_(NULL, 0, sizeof(BackRefNode))); | 187 reinterpret_cast<BackRefNode*>(alloc_(NULL, 0, sizeof(BackRefNode))); |
| 172 value->set_reference(reference); | 188 value->set_reference(reference); |
| 173 value->set_state(state); | 189 value->set_state(state); |
| 174 return value; | 190 return value; |
| 175 } | 191 } |
| 176 | 192 |
| 177 | 193 |
| 178 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 194 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
| 179 // Read the class header information and lookup the class. | 195 // Read the class header information and lookup the class. |
| 180 intptr_t class_header = ReadIntptrValue(); | 196 intptr_t class_header = ReadIntptrValue(); |
| 181 intptr_t tags = ReadIntptrValue(); | 197 intptr_t tags = ReadIntptrValue(); |
| 182 USE(tags); | 198 USE(tags); |
| 183 intptr_t class_id; | 199 intptr_t class_id; |
| 184 | 200 |
| 185 // Reading of regular dart instances is not supported. | 201 // There is limited support for reading regular dart instances. Only |
| 202 // typed data views are currently handled. |
| 186 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 203 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 187 return AllocateDartCObjectUnsupported(); | 204 Dart_CObject_Internal* object = |
| 205 reinterpret_cast<Dart_CObject_Internal*>(GetBackRef(object_id)); |
| 206 if (object == NULL) { |
| 207 object = |
| 208 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); |
| 209 AddBackRef(object_id, object, kIsDeserialized); |
| 210 // Read class of object. |
| 211 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); |
| 212 ASSERT(object->cls->type == |
| 213 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kClass)); |
| 214 } |
| 215 ASSERT(object->type == |
| 216 static_cast<Dart_CObject::Type>( |
| 217 Dart_CObject_Internal::kUninitialized)); |
| 218 |
| 219 // Handle typed data views. |
| 220 char* library_url = |
| 221 object->cls->internal.as_class.library_url->value.as_string; |
| 222 char* class_name = |
| 223 object->cls->internal.as_class.class_name->value.as_string; |
| 224 if (strcmp("dart:typeddata", library_url) == 0 && |
| 225 strncmp("_Uint8ArrayView", class_name, 15) == 0) { |
| 226 object->type = |
| 227 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kView); |
| 228 // Skip type arguments. |
| 229 ReadObjectImpl(); |
| 230 object->internal.as_view.buffer = ReadObjectImpl(); |
| 231 object->internal.as_view.offset_in_bytes = ReadSmiValue(); |
| 232 object->internal.as_view.length = ReadSmiValue(); |
| 233 |
| 234 // The buffer is fully read now as typed data objects are |
| 235 // serialized in-line. |
| 236 Dart_CObject* buffer = object->internal.as_view.buffer; |
| 237 ASSERT(buffer->type == Dart_CObject::kUint8Array); |
| 238 |
| 239 // Now turn the view into a byte array. |
| 240 object->type = Dart_CObject::kUint8Array; |
| 241 object->value.as_byte_array.length = object->internal.as_view.length; |
| 242 object->value.as_byte_array.values = |
| 243 buffer->value.as_byte_array.values + |
| 244 object->internal.as_view.offset_in_bytes; |
| 245 } else { |
| 246 // TODO(sgjesse): Handle other instances. Currently this will |
| 247 // skew the reading as the fields of the instance is not read. |
| 248 } |
| 249 return object; |
| 188 } | 250 } |
| 189 | 251 |
| 190 ASSERT((class_header & kSmiTagMask) != 0); | 252 ASSERT((class_header & kSmiTagMask) != 0); |
| 191 class_id = LookupInternalClass(class_header); | 253 class_id = LookupInternalClass(class_header); |
| 192 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { | 254 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { |
| 193 intptr_t len = ReadSmiValue(); | 255 intptr_t len = ReadSmiValue(); |
| 194 Dart_CObject* value = GetBackRef(object_id); | 256 Dart_CObject* value = GetBackRef(object_id); |
| 195 if (value == NULL) { | 257 if (value == NULL) { |
| 196 value = AllocateDartCObjectArray(len); | 258 value = AllocateDartCObjectArray(len); |
| 197 AddBackRef(object_id, value, kIsDeserialized); | 259 AddBackRef(object_id, value, kIsDeserialized); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (IsVMIsolateObject(value)) { | 320 if (IsVMIsolateObject(value)) { |
| 259 return ReadVMIsolateObject(value); | 321 return ReadVMIsolateObject(value); |
| 260 } | 322 } |
| 261 if (SerializedHeaderTag::decode(value) == kObjectId) { | 323 if (SerializedHeaderTag::decode(value) == kObjectId) { |
| 262 return ReadIndexedObject(SerializedHeaderData::decode(value)); | 324 return ReadIndexedObject(SerializedHeaderData::decode(value)); |
| 263 } | 325 } |
| 264 ASSERT(SerializedHeaderTag::decode(value) == kInlined); | 326 ASSERT(SerializedHeaderTag::decode(value) == kInlined); |
| 265 // Read the class header information and lookup the class. | 327 // Read the class header information and lookup the class. |
| 266 intptr_t class_header = ReadIntptrValue(); | 328 intptr_t class_header = ReadIntptrValue(); |
| 267 | 329 |
| 268 // Reading of regular dart instances is not supported. | 330 // Reading of regular dart instances has limited support in order to |
| 331 // read typed data views. |
| 269 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 332 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 270 intptr_t object_id = SerializedHeaderData::decode(value); | 333 intptr_t object_id = SerializedHeaderData::decode(value); |
| 271 Dart_CObject* object = AllocateDartCObjectUnsupported(); | 334 Dart_CObject_Internal* object = |
| 335 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); |
| 272 AddBackRef(object_id, object, kIsNotDeserialized); | 336 AddBackRef(object_id, object, kIsNotDeserialized); |
| 337 // Read class of object. |
| 338 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); |
| 339 ASSERT(object->cls->type == |
| 340 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kClass)); |
| 273 return object; | 341 return object; |
| 274 } | 342 } |
| 275 ASSERT((class_header & kSmiTagMask) != 0); | 343 ASSERT((class_header & kSmiTagMask) != 0); |
| 276 intptr_t object_id = SerializedHeaderData::decode(value); | 344 intptr_t object_id = SerializedHeaderData::decode(value); |
| 277 intptr_t class_id = LookupInternalClass(class_header); | 345 intptr_t class_id = LookupInternalClass(class_header); |
| 278 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { | 346 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { |
| 279 ASSERT(GetBackRef(object_id) == NULL); | 347 ASSERT(GetBackRef(object_id) == NULL); |
| 280 intptr_t len = ReadSmiValue(); | 348 intptr_t len = ReadSmiValue(); |
| 281 Dart_CObject* value = AllocateDartCObjectArray(len); | 349 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 282 AddBackRef(object_id, value, kIsNotDeserialized); | 350 AddBackRef(object_id, value, kIsNotDeserialized); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 306 } | 374 } |
| 307 // No other VM isolate objects are supported. | 375 // No other VM isolate objects are supported. |
| 308 return AllocateDartCObjectNull(); | 376 return AllocateDartCObjectNull(); |
| 309 } | 377 } |
| 310 | 378 |
| 311 | 379 |
| 312 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, | 380 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, |
| 313 intptr_t object_id) { | 381 intptr_t object_id) { |
| 314 switch (class_id) { | 382 switch (class_id) { |
| 315 case kClassCid: { | 383 case kClassCid: { |
| 316 Dart_CObject* object = AllocateDartCObjectUnsupported(); | 384 Dart_CObject_Internal* object = AllocateDartCObjectClass(); |
| 317 AddBackRef(object_id, object, kIsDeserialized); | 385 AddBackRef(object_id, object, kIsDeserialized); |
| 386 object->internal.as_class.library_url = ReadObjectImpl(); |
| 387 ASSERT(object->internal.as_class.library_url->type == |
| 388 Dart_CObject::kString); |
| 389 object->internal.as_class.class_name = ReadObjectImpl(); |
| 390 ASSERT(object->internal.as_class.class_name->type == |
| 391 Dart_CObject::kString); |
| 318 return object; | 392 return object; |
| 319 } | 393 } |
| 320 case kTypeArgumentsCid: { | 394 case kTypeArgumentsCid: { |
| 321 // TODO(sjesse): Remove this when message serialization format is | 395 // TODO(sjesse): Remove this when message serialization format is |
| 322 // updated (currently length is leaked). | 396 // updated (currently length is leaked). |
| 323 Dart_CObject* value = &type_arguments_marker; | 397 Dart_CObject* value = &type_arguments_marker; |
| 324 AddBackRef(object_id, value, kIsDeserialized); | 398 AddBackRef(object_id, value, kIsDeserialized); |
| 325 Dart_CObject* length = ReadObjectImpl(); | 399 Dart_CObject* length = ReadObjectImpl(); |
| 326 ASSERT(length->type == Dart_CObject::kInt32); | 400 ASSERT(length->type == Dart_CObject::kInt32); |
| 327 for (int i = 0; i < length->value.as_int32; i++) { | 401 for (int i = 0; i < length->value.as_int32; i++) { |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 if (!success) { | 984 if (!success) { |
| 911 UnmarkAllCObjects(object); | 985 UnmarkAllCObjects(object); |
| 912 return false; | 986 return false; |
| 913 } | 987 } |
| 914 } | 988 } |
| 915 UnmarkAllCObjects(object); | 989 UnmarkAllCObjects(object); |
| 916 return true; | 990 return true; |
| 917 } | 991 } |
| 918 | 992 |
| 919 } // namespace dart | 993 } // namespace dart |
| OLD | NEW |