| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); | 49 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); |
| 50 ASSERT(header_type == kObjectId); | 50 ASSERT(header_type == kObjectId); |
| 51 intptr_t header_value = SerializedHeaderData::decode(class_header); | 51 intptr_t header_value = SerializedHeaderData::decode(class_header); |
| 52 return header_value; | 52 return header_value; |
| 53 } | 53 } |
| 54 | 54 |
| 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 value->type = type; | 60 value->type = type; |
| 60 return value; | 61 return value; |
| 61 } | 62 } |
| 62 | 63 |
| 63 | 64 |
| 64 Dart_CObject* ApiMessageReader::AllocateDartCObjectNull() { | 65 Dart_CObject* ApiMessageReader::AllocateDartCObjectNull() { |
| 65 return AllocateDartCObject(Dart_CObject::kNull); | 66 return AllocateDartCObject(Dart_CObject::kNull); |
| 66 } | 67 } |
| 67 | 68 |
| 68 | 69 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 87 } | 88 } |
| 88 | 89 |
| 89 | 90 |
| 90 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { | 91 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { |
| 91 // Allocate a Dart_CObject structure followed by an array of chars | 92 // Allocate a Dart_CObject structure followed by an array of chars |
| 92 // for the string content. The pointer to the string content is set | 93 // for the string content. The pointer to the string content is set |
| 93 // up to this area. | 94 // up to this area. |
| 94 Dart_CObject* value = | 95 Dart_CObject* value = |
| 95 reinterpret_cast<Dart_CObject*>( | 96 reinterpret_cast<Dart_CObject*>( |
| 96 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); | 97 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
| 98 ASSERT(value != NULL); |
| 97 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); | 99 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); |
| 98 value->type = Dart_CObject::kString; | 100 value->type = Dart_CObject::kString; |
| 99 return value; | 101 return value; |
| 100 } | 102 } |
| 101 | 103 |
| 102 | 104 |
| 105 Dart_CObject* ApiMessageReader::AllocateDartCObjectByteArray(intptr_t length) { |
| 106 // Allocate a Dart_CObject structure followed by an array of bytes |
| 107 // for the byte array content. The pointer to the byte array content |
| 108 // is set up to this area. |
| 109 Dart_CObject* value = |
| 110 reinterpret_cast<Dart_CObject*>( |
| 111 alloc_(NULL, 0, sizeof(Dart_CObject) + length)); |
| 112 ASSERT(value != NULL); |
| 113 value->type = Dart_CObject::kByteArray; |
| 114 value->value.as_array.length = length; |
| 115 if (length > 0) { |
| 116 value->value.as_byte_array.values = |
| 117 reinterpret_cast<uint8_t*>(value) + sizeof(*value); |
| 118 } else { |
| 119 value->value.as_byte_array.values = NULL; |
| 120 } |
| 121 return value; |
| 122 } |
| 123 |
| 124 |
| 103 Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) { | 125 Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) { |
| 104 // Allocate a Dart_CObject structure followed by an array of | 126 // Allocate a Dart_CObject structure followed by an array of |
| 105 // pointers to Dart_CObject structures. The pointer to the array | 127 // pointers to Dart_CObject structures. The pointer to the array |
| 106 // content is set up to this area. | 128 // content is set up to this area. |
| 107 Dart_CObject* value = | 129 Dart_CObject* value = |
| 108 reinterpret_cast<Dart_CObject*>( | 130 reinterpret_cast<Dart_CObject*>( |
| 109 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); | 131 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); |
| 132 ASSERT(value != NULL); |
| 110 value->type = Dart_CObject::kArray; | 133 value->type = Dart_CObject::kArray; |
| 111 value->value.as_array.length = length; | 134 value->value.as_array.length = length; |
| 112 if (length > 0) { | 135 if (length > 0) { |
| 113 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 136 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
| 114 } else { | 137 } else { |
| 115 value->value.as_array.values = NULL; | 138 value->value.as_array.values = NULL; |
| 116 } | 139 } |
| 117 return value; | 140 return value; |
| 118 } | 141 } |
| 119 | 142 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 break; | 198 break; |
| 176 } | 199 } |
| 177 case ObjectStore::kOneByteStringClass: { | 200 case ObjectStore::kOneByteStringClass: { |
| 178 intptr_t len = ReadSmiValue(); | 201 intptr_t len = ReadSmiValue(); |
| 179 intptr_t hash = ReadSmiValue(); | 202 intptr_t hash = ReadSmiValue(); |
| 180 USE(hash); | 203 USE(hash); |
| 181 Dart_CObject* object = AllocateDartCObjectString(len); | 204 Dart_CObject* object = AllocateDartCObjectString(len); |
| 182 AddBackwardReference(object_id, object); | 205 AddBackwardReference(object_id, object); |
| 183 char* p = object->value.as_string; | 206 char* p = object->value.as_string; |
| 184 for (intptr_t i = 0; i < len; i++) { | 207 for (intptr_t i = 0; i < len; i++) { |
| 185 *p = Read<uint8_t>(); | 208 p[i] = Read<uint8_t>(); |
| 186 p++; | |
| 187 } | 209 } |
| 188 *p = '\0'; | 210 p[len] = '\0'; |
| 189 return object; | 211 return object; |
| 190 break; | 212 break; |
| 191 } | 213 } |
| 192 case ObjectStore::kTwoByteStringClass: | 214 case ObjectStore::kTwoByteStringClass: |
| 193 // Two byte strings not supported. | 215 // Two byte strings not supported. |
| 194 return NULL; | 216 return NULL; |
| 195 break; | 217 break; |
| 196 case ObjectStore::kFourByteStringClass: | 218 case ObjectStore::kFourByteStringClass: |
| 197 // Four byte strings not supported. | 219 // Four byte strings not supported. |
| 198 return NULL; | 220 return NULL; |
| 199 break; | 221 break; |
| 222 case ObjectStore::kInternalByteArrayClass: { |
| 223 intptr_t len = ReadSmiValue(); |
| 224 Dart_CObject* object = AllocateDartCObjectByteArray(len); |
| 225 AddBackwardReference(object_id, object); |
| 226 if (len > 0) { |
| 227 uint8_t* p = object->value.as_byte_array.values; |
| 228 for (intptr_t i = 0; i < len; i++) { |
| 229 p[i] = Read<uint8_t>(); |
| 230 } |
| 231 } |
| 232 return object; |
| 233 break; |
| 234 } |
| 200 default: | 235 default: |
| 201 // Everything else not supported. | 236 // Everything else not supported. |
| 202 return NULL; | 237 return NULL; |
| 203 } | 238 } |
| 204 } | 239 } |
| 205 | 240 |
| 206 | 241 |
| 207 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { | 242 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { |
| 208 if (object_id == Object::kNullObject) { | 243 if (object_id == Object::kNullObject) { |
| 209 return AllocateDartCObjectNull(); | 244 return AllocateDartCObjectNull(); |
| 210 } else if (object_id == ObjectStore::kTrueValue) { | 245 } else if (object_id == ObjectStore::kTrueValue) { |
| 211 return AllocateDartCObjectBool(true); | 246 return AllocateDartCObjectBool(true); |
| 212 } else if (object_id == ObjectStore::kFalseValue) { | 247 } else if (object_id == ObjectStore::kFalseValue) { |
| 213 return AllocateDartCObjectBool(false); | 248 return AllocateDartCObjectBool(false); |
| 214 } else if (object_id == ObjectStore::kDynamicType || | 249 } else if (object_id == ObjectStore::kDynamicType || |
| 215 object_id == ObjectStore::kDoubleInterface || | 250 object_id == ObjectStore::kDoubleInterface || |
| 216 object_id == ObjectStore::kIntInterface || | 251 object_id == ObjectStore::kIntInterface || |
| 217 object_id == ObjectStore::kBoolInterface || | 252 object_id == ObjectStore::kBoolInterface || |
| 218 object_id == ObjectStore::kStringInterface) { | 253 object_id == ObjectStore::kStringInterface || |
| 254 object_id == ObjectStore::kByteArrayInterface) { |
| 219 // Always return dynamic type (this is only a marker). | 255 // Always return dynamic type (this is only a marker). |
| 220 return &dynamic_type_marker; | 256 return &dynamic_type_marker; |
| 221 } else { | 257 } else { |
| 222 intptr_t index = object_id - kMaxPredefinedObjectIds; | 258 intptr_t index = object_id - kMaxPredefinedObjectIds; |
| 223 ASSERT(index < backward_references_.length()); | 259 ASSERT(index < backward_references_.length()); |
| 224 ASSERT(backward_references_[index] != NULL); | 260 ASSERT(backward_references_[index] != NULL); |
| 225 return backward_references_[index]; | 261 return backward_references_[index]; |
| 226 } | 262 } |
| 227 return NULL; | 263 return NULL; |
| 228 } | 264 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 250 return ReadObjectImpl(value); | 286 return ReadObjectImpl(value); |
| 251 } | 287 } |
| 252 | 288 |
| 253 | 289 |
| 254 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { | 290 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { |
| 255 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); | 291 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); |
| 256 backward_references_.Add(obj); | 292 backward_references_.Add(obj); |
| 257 } | 293 } |
| 258 | 294 |
| 259 } // namespace dart | 295 } // namespace dart |
| OLD | NEW |