| 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 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 void ApiMessageReader::Init() { | 26 void ApiMessageReader::Init() { |
| 27 // Initialize marker objects used to handle Lists. | 27 // Initialize marker objects used to handle Lists. |
| 28 // TODO(sjesse): Remove this when message serialization format is | 28 // TODO(sjesse): Remove this when message serialization format is |
| 29 // updated. | 29 // updated. |
| 30 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); | 30 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); |
| 31 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); | 31 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); |
| 32 type_arguments_marker.type = | 32 type_arguments_marker.type = |
| 33 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); | 33 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kTypeArguments); |
| 34 dynamic_type_marker.type = | 34 dynamic_type_marker.type = |
| 35 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); | 35 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kDynamicType); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 Dart_CObject* ApiMessageReader::ReadMessage() { | 39 Dart_CObject* ApiMessageReader::ReadMessage() { |
| 40 // Read the object out of the message. | 40 // Read the object out of the message. |
| 41 return ReadObject(); | 41 return ReadObject(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 intptr_t ApiMessageReader::LookupInternalClass(intptr_t class_header) { | 45 intptr_t ApiMessageReader::LookupInternalClass(intptr_t class_header) { |
| 46 if (IsVMIsolateObject(class_header)) { | 46 if (IsVMIsolateObject(class_header)) { |
| 47 return GetVMIsolateObjectId(class_header); | 47 return GetVMIsolateObjectId(class_header); |
| 48 } | 48 } |
| 49 ASSERT(SerializedHeaderTag::decode(class_header) == kObjectId); | 49 ASSERT(SerializedHeaderTag::decode(class_header) == kObjectId); |
| 50 return SerializedHeaderData::decode(class_header); | 50 return SerializedHeaderData::decode(class_header); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject::Type type) { | 54 Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject_Type type) { |
| 55 Dart_CObject* value = | 55 Dart_CObject* value = |
| 56 reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject))); | 56 reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject))); |
| 57 ASSERT(value != NULL); | 57 ASSERT(value != NULL); |
| 58 value->type = type; | 58 value->type = type; |
| 59 return value; | 59 return value; |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 Dart_CObject* ApiMessageReader::AllocateDartCObjectUnsupported() { | 63 Dart_CObject* ApiMessageReader::AllocateDartCObjectUnsupported() { |
| 64 return AllocateDartCObject(Dart_CObject::kUnsupported); | 64 return AllocateDartCObject(Dart_CObject_kUnsupported); |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 Dart_CObject* ApiMessageReader::AllocateDartCObjectNull() { | 68 Dart_CObject* ApiMessageReader::AllocateDartCObjectNull() { |
| 69 return AllocateDartCObject(Dart_CObject::kNull); | 69 return AllocateDartCObject(Dart_CObject_kNull); |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 Dart_CObject* ApiMessageReader::AllocateDartCObjectBool(bool val) { | 73 Dart_CObject* ApiMessageReader::AllocateDartCObjectBool(bool val) { |
| 74 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kBool); | 74 Dart_CObject* value = AllocateDartCObject(Dart_CObject_kBool); |
| 75 value->value.as_bool = val; | 75 value->value.as_bool = val; |
| 76 return value; | 76 return value; |
| 77 } | 77 } |
| 78 | 78 |
| 79 | 79 |
| 80 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt32(int32_t val) { | 80 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt32(int32_t val) { |
| 81 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt32); | 81 Dart_CObject* value = AllocateDartCObject(Dart_CObject_kInt32); |
| 82 value->value.as_int32 = val; | 82 value->value.as_int32 = val; |
| 83 return value; | 83 return value; |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt64(int64_t val) { | 87 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt64(int64_t val) { |
| 88 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt64); | 88 Dart_CObject* value = AllocateDartCObject(Dart_CObject_kInt64); |
| 89 value->value.as_int64 = val; | 89 value->value.as_int64 = val; |
| 90 return value; | 90 return value; |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 Dart_CObject* ApiMessageReader::AllocateDartCObjectBigint(intptr_t length) { | 94 Dart_CObject* ApiMessageReader::AllocateDartCObjectBigint(intptr_t length) { |
| 95 // Allocate a Dart_CObject structure followed by an array of chars | 95 // Allocate a Dart_CObject structure followed by an array of chars |
| 96 // for the bigint hex string content. The pointer to the bigint | 96 // for the bigint hex string content. The pointer to the bigint |
| 97 // content is set up to this area. | 97 // content is set up to this area. |
| 98 Dart_CObject* value = | 98 Dart_CObject* value = |
| 99 reinterpret_cast<Dart_CObject*>( | 99 reinterpret_cast<Dart_CObject*>( |
| 100 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); | 100 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
| 101 value->value.as_bigint = reinterpret_cast<char*>(value) + sizeof(*value); | 101 value->value.as_bigint = reinterpret_cast<char*>(value) + sizeof(*value); |
| 102 value->type = Dart_CObject::kBigint; | 102 value->type = Dart_CObject_kBigint; |
| 103 return value; | 103 return value; |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { | 107 Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { |
| 108 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); | 108 Dart_CObject* value = AllocateDartCObject(Dart_CObject_kDouble); |
| 109 value->value.as_double = val; | 109 value->value.as_double = val; |
| 110 return value; | 110 return value; |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { | 114 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { |
| 115 // Allocate a Dart_CObject structure followed by an array of chars | 115 // Allocate a Dart_CObject structure followed by an array of chars |
| 116 // for the string content. The pointer to the string content is set | 116 // for the string content. The pointer to the string content is set |
| 117 // up to this area. | 117 // up to this area. |
| 118 Dart_CObject* value = | 118 Dart_CObject* value = |
| 119 reinterpret_cast<Dart_CObject*>( | 119 reinterpret_cast<Dart_CObject*>( |
| 120 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); | 120 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
| 121 ASSERT(value != NULL); | 121 ASSERT(value != NULL); |
| 122 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); | 122 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); |
| 123 value->type = Dart_CObject::kString; | 123 value->type = Dart_CObject_kString; |
| 124 return value; | 124 return value; |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 static int GetTypedDataSizeInBytes(Dart_CObject::TypedDataType type) { | 128 static int GetTypedDataSizeInBytes(Dart_TypedData_Type type) { |
| 129 switch (type) { | 129 switch (type) { |
| 130 case Dart_CObject::kInt8Array: | 130 case Dart_TypedData_kInt8: |
| 131 case Dart_CObject::kUint8Array: | 131 case Dart_TypedData_kUint8: |
| 132 case Dart_CObject::kUint8ClampedArray: | 132 case Dart_TypedData_kUint8Clamped: |
| 133 return 1; | 133 return 1; |
| 134 case Dart_CObject::kInt16Array: | 134 case Dart_TypedData_kInt16: |
| 135 case Dart_CObject::kUint16Array: | 135 case Dart_TypedData_kUint16: |
| 136 return 2; | 136 return 2; |
| 137 case Dart_CObject::kInt32Array: | 137 case Dart_TypedData_kInt32: |
| 138 case Dart_CObject::kUint32Array: | 138 case Dart_TypedData_kUint32: |
| 139 case Dart_CObject::kFloat32Array: | 139 case Dart_TypedData_kFloat32: |
| 140 return 4; | 140 return 4; |
| 141 case Dart_CObject::kInt64Array: | 141 case Dart_TypedData_kInt64: |
| 142 case Dart_CObject::kUint64Array: | 142 case Dart_TypedData_kUint64: |
| 143 case Dart_CObject::kFloat64Array: | 143 case Dart_TypedData_kFloat64: |
| 144 return 8; | 144 return 8; |
| 145 default: | 145 default: |
| 146 break; | 146 break; |
| 147 } | 147 } |
| 148 UNREACHABLE(); | 148 UNREACHABLE(); |
| 149 return -1; | 149 return -1; |
| 150 } | 150 } |
| 151 | 151 |
| 152 | 152 |
| 153 Dart_CObject* ApiMessageReader::AllocateDartCObjectTypedData( | 153 Dart_CObject* ApiMessageReader::AllocateDartCObjectTypedData( |
| 154 Dart_CObject::TypedDataType type, intptr_t length) { | 154 Dart_TypedData_Type type, intptr_t length) { |
| 155 // Allocate a Dart_CObject structure followed by an array of bytes | 155 // Allocate a Dart_CObject structure followed by an array of bytes |
| 156 // for the byte array content. The pointer to the byte array content | 156 // for the byte array content. The pointer to the byte array content |
| 157 // is set up to this area. | 157 // is set up to this area. |
| 158 intptr_t length_in_bytes = GetTypedDataSizeInBytes(type) * length; | 158 intptr_t length_in_bytes = GetTypedDataSizeInBytes(type) * length; |
| 159 Dart_CObject* value = | 159 Dart_CObject* value = |
| 160 reinterpret_cast<Dart_CObject*>( | 160 reinterpret_cast<Dart_CObject*>( |
| 161 alloc_(NULL, 0, sizeof(Dart_CObject) + length_in_bytes)); | 161 alloc_(NULL, 0, sizeof(Dart_CObject) + length_in_bytes)); |
| 162 ASSERT(value != NULL); | 162 ASSERT(value != NULL); |
| 163 value->type = Dart_CObject::kTypedData; | 163 value->type = Dart_CObject_kTypedData; |
| 164 value->value.as_typed_data.type = type; | 164 value->value.as_typed_data.type = type; |
| 165 value->value.as_typed_data.length = length_in_bytes; | 165 value->value.as_typed_data.length = length_in_bytes; |
| 166 if (length > 0) { | 166 if (length > 0) { |
| 167 value->value.as_typed_data.values = | 167 value->value.as_typed_data.values = |
| 168 reinterpret_cast<uint8_t*>(value) + sizeof(*value); | 168 reinterpret_cast<uint8_t*>(value) + sizeof(*value); |
| 169 } else { | 169 } else { |
| 170 value->value.as_typed_data.values = NULL; | 170 value->value.as_typed_data.values = NULL; |
| 171 } | 171 } |
| 172 return value; | 172 return value; |
| 173 } | 173 } |
| 174 | 174 |
| 175 | 175 |
| 176 Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) { | 176 Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) { |
| 177 // Allocate a Dart_CObject structure followed by an array of | 177 // Allocate a Dart_CObject structure followed by an array of |
| 178 // pointers to Dart_CObject structures. The pointer to the array | 178 // pointers to Dart_CObject structures. The pointer to the array |
| 179 // content is set up to this area. | 179 // content is set up to this area. |
| 180 Dart_CObject* value = | 180 Dart_CObject* value = |
| 181 reinterpret_cast<Dart_CObject*>( | 181 reinterpret_cast<Dart_CObject*>( |
| 182 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); | 182 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); |
| 183 ASSERT(value != NULL); | 183 ASSERT(value != NULL); |
| 184 value->type = Dart_CObject::kArray; | 184 value->type = Dart_CObject_kArray; |
| 185 value->value.as_array.length = length; | 185 value->value.as_array.length = length; |
| 186 if (length > 0) { | 186 if (length > 0) { |
| 187 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 187 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
| 188 } else { | 188 } else { |
| 189 value->value.as_array.values = NULL; | 189 value->value.as_array.values = NULL; |
| 190 } | 190 } |
| 191 return value; | 191 return value; |
| 192 } | 192 } |
| 193 | 193 |
| 194 | 194 |
| 195 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal( | 195 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal( |
| 196 Dart_CObject_Internal::Type type) { | 196 Dart_CObject_Internal::Type type) { |
| 197 Dart_CObject_Internal* value = | 197 Dart_CObject_Internal* value = |
| 198 reinterpret_cast<Dart_CObject_Internal*>( | 198 reinterpret_cast<Dart_CObject_Internal*>( |
| 199 alloc_(NULL, 0, sizeof(Dart_CObject_Internal))); | 199 alloc_(NULL, 0, sizeof(Dart_CObject_Internal))); |
| 200 ASSERT(value != NULL); | 200 ASSERT(value != NULL); |
| 201 value->type = static_cast<Dart_CObject::Type>(type); | 201 value->type = static_cast<Dart_CObject_Type>(type); |
| 202 return value; | 202 return value; |
| 203 } | 203 } |
| 204 | 204 |
| 205 | 205 |
| 206 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectClass() { | 206 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectClass() { |
| 207 return AllocateDartCObjectInternal(Dart_CObject_Internal::kClass); | 207 return AllocateDartCObjectInternal(Dart_CObject_Internal::kClass); |
| 208 } | 208 } |
| 209 | 209 |
| 210 | 210 |
| 211 ApiMessageReader::BackRefNode* ApiMessageReader::AllocateBackRefNode( | 211 ApiMessageReader::BackRefNode* ApiMessageReader::AllocateBackRefNode( |
| 212 Dart_CObject* reference, | 212 Dart_CObject* reference, |
| 213 DeserializeState state) { | 213 DeserializeState state) { |
| 214 BackRefNode* value = | 214 BackRefNode* value = |
| 215 reinterpret_cast<BackRefNode*>(alloc_(NULL, 0, sizeof(BackRefNode))); | 215 reinterpret_cast<BackRefNode*>(alloc_(NULL, 0, sizeof(BackRefNode))); |
| 216 value->set_reference(reference); | 216 value->set_reference(reference); |
| 217 value->set_state(state); | 217 value->set_state(state); |
| 218 return value; | 218 return value; |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 static Dart_CObject::TypedDataType GetTypedDataTypeFromView( | 222 static Dart_TypedData_Type GetTypedDataTypeFromView( |
| 223 Dart_CObject_Internal* object) { | 223 Dart_CObject_Internal* object) { |
| 224 struct { | 224 struct { |
| 225 const char* name; | 225 const char* name; |
| 226 Dart_CObject::TypedDataType type; | 226 Dart_TypedData_Type type; |
| 227 } view_class_names[] = { | 227 } view_class_names[] = { |
| 228 { "_Int8ArrayView", Dart_CObject::kInt8Array }, | 228 { "_Int8ArrayView", Dart_TypedData_kInt8 }, |
| 229 { "_Uint8ArrayView", Dart_CObject::kUint8Array }, | 229 { "_Uint8ArrayView", Dart_TypedData_kUint8 }, |
| 230 { "_Uint8ClampedArrayView", Dart_CObject::kUint8ClampedArray }, | 230 { "_Uint8ClampedArrayView", Dart_TypedData_kUint8Clamped }, |
| 231 { "_Int16ArrayView", Dart_CObject::kInt16Array }, | 231 { "_Int16ArrayView", Dart_TypedData_kInt16 }, |
| 232 { "_Uint16ArrayView", Dart_CObject::kUint16Array }, | 232 { "_Uint16ArrayView", Dart_TypedData_kUint16 }, |
| 233 { "_Int32ArrayView", Dart_CObject::kInt32Array }, | 233 { "_Int32ArrayView", Dart_TypedData_kInt32 }, |
| 234 { "_Uint32ArrayView", Dart_CObject::kUint32Array }, | 234 { "_Uint32ArrayView", Dart_TypedData_kUint32 }, |
| 235 { "_Int64ArrayView", Dart_CObject::kInt64Array }, | 235 { "_Int64ArrayView", Dart_TypedData_kInt64 }, |
| 236 { "_Uint64ArrayView", Dart_CObject::kUint64Array }, | 236 { "_Uint64ArrayView", Dart_TypedData_kUint64 }, |
| 237 { "_ByteDataView", Dart_CObject::kUint8Array }, | 237 { "_ByteDataView", Dart_TypedData_kUint8 }, |
| 238 { "_Float32ArrayView", Dart_CObject::kFloat32Array }, | 238 { "_Float32ArrayView", Dart_TypedData_kFloat32 }, |
| 239 { "_Float64ArrayView", Dart_CObject::kFloat64Array }, | 239 { "_Float64ArrayView", Dart_TypedData_kFloat64 }, |
| 240 { NULL, Dart_CObject::kNumberOfTypedDataTypes }, | 240 { NULL, Dart_TypedData_kInvalid }, |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 char* library_url = | 243 char* library_url = |
| 244 object->cls->internal.as_class.library_url->value.as_string; | 244 object->cls->internal.as_class.library_url->value.as_string; |
| 245 char* class_name = | 245 char* class_name = |
| 246 object->cls->internal.as_class.class_name->value.as_string; | 246 object->cls->internal.as_class.class_name->value.as_string; |
| 247 if (strcmp("dart:typed_data", library_url) != 0) { | 247 if (strcmp("dart:typed_data", library_url) != 0) { |
| 248 return Dart_CObject::kNumberOfTypedDataTypes; | 248 return Dart_TypedData_kInvalid; |
| 249 } | 249 } |
| 250 int i = 0; | 250 int i = 0; |
| 251 while (view_class_names[i].name != NULL) { | 251 while (view_class_names[i].name != NULL) { |
| 252 if (strncmp(view_class_names[i].name, | 252 if (strncmp(view_class_names[i].name, |
| 253 class_name, | 253 class_name, |
| 254 strlen(view_class_names[i].name)) == 0) { | 254 strlen(view_class_names[i].name)) == 0) { |
| 255 return view_class_names[i].type; | 255 return view_class_names[i].type; |
| 256 } | 256 } |
| 257 i++; | 257 i++; |
| 258 } | 258 } |
| 259 return Dart_CObject::kNumberOfTypedDataTypes; | 259 return Dart_TypedData_kInvalid; |
| 260 } | 260 } |
| 261 | 261 |
| 262 | 262 |
| 263 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 263 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
| 264 // Read the class header information and lookup the class. | 264 // Read the class header information and lookup the class. |
| 265 intptr_t class_header = ReadIntptrValue(); | 265 intptr_t class_header = ReadIntptrValue(); |
| 266 intptr_t tags = ReadIntptrValue(); | 266 intptr_t tags = ReadIntptrValue(); |
| 267 USE(tags); | 267 USE(tags); |
| 268 intptr_t class_id; | 268 intptr_t class_id; |
| 269 | 269 |
| 270 // There is limited support for reading regular dart instances. Only | 270 // There is limited support for reading regular dart instances. Only |
| 271 // typed data views are currently handled. | 271 // typed data views are currently handled. |
| 272 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 272 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 273 Dart_CObject_Internal* object = | 273 Dart_CObject_Internal* object = |
| 274 reinterpret_cast<Dart_CObject_Internal*>(GetBackRef(object_id)); | 274 reinterpret_cast<Dart_CObject_Internal*>(GetBackRef(object_id)); |
| 275 if (object == NULL) { | 275 if (object == NULL) { |
| 276 object = | 276 object = |
| 277 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); | 277 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); |
| 278 AddBackRef(object_id, object, kIsDeserialized); | 278 AddBackRef(object_id, object, kIsDeserialized); |
| 279 // Read class of object. | 279 // Read class of object. |
| 280 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); | 280 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); |
| 281 ASSERT(object->cls->type == | 281 ASSERT(object->cls->type == |
| 282 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kClass)); | 282 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kClass)); |
| 283 } | 283 } |
| 284 ASSERT(object->type == | 284 ASSERT(object->type == |
| 285 static_cast<Dart_CObject::Type>( | 285 static_cast<Dart_CObject_Type>( |
| 286 Dart_CObject_Internal::kUninitialized)); | 286 Dart_CObject_Internal::kUninitialized)); |
| 287 | 287 |
| 288 // Handle typed data views. | 288 // Handle typed data views. |
| 289 Dart_CObject::TypedDataType type = GetTypedDataTypeFromView(object); | 289 Dart_TypedData_Type type = GetTypedDataTypeFromView(object); |
| 290 if (type != Dart_CObject::kNumberOfTypedDataTypes) { | 290 if (type != Dart_TypedData_kInvalid) { |
| 291 object->type = | 291 object->type = |
| 292 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kView); | 292 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kView); |
| 293 ReadObjectImpl(); // Skip type arguments. | 293 ReadObjectImpl(); // Skip type arguments. |
| 294 object->internal.as_view.buffer = ReadObjectImpl(); | 294 object->internal.as_view.buffer = ReadObjectImpl(); |
| 295 object->internal.as_view.offset_in_bytes = ReadSmiValue(); | 295 object->internal.as_view.offset_in_bytes = ReadSmiValue(); |
| 296 object->internal.as_view.length = ReadSmiValue(); | 296 object->internal.as_view.length = ReadSmiValue(); |
| 297 ReadObjectImpl(); // Skip last field. | 297 ReadObjectImpl(); // Skip last field. |
| 298 | 298 |
| 299 // The buffer is fully read now as typed data objects are | 299 // The buffer is fully read now as typed data objects are |
| 300 // serialized in-line. | 300 // serialized in-line. |
| 301 Dart_CObject* buffer = object->internal.as_view.buffer; | 301 Dart_CObject* buffer = object->internal.as_view.buffer; |
| 302 ASSERT(buffer->type == Dart_CObject::kTypedData); | 302 ASSERT(buffer->type == Dart_CObject_kTypedData); |
| 303 | 303 |
| 304 // Now turn the view into a byte array. | 304 // Now turn the view into a byte array. |
| 305 object->type = Dart_CObject::kTypedData; | 305 object->type = Dart_CObject_kTypedData; |
| 306 object->value.as_typed_data.type = type; | 306 object->value.as_typed_data.type = type; |
| 307 object->value.as_typed_data.length = | 307 object->value.as_typed_data.length = |
| 308 object->internal.as_view.length * | 308 object->internal.as_view.length * |
| 309 GetTypedDataSizeInBytes(type); | 309 GetTypedDataSizeInBytes(type); |
| 310 object->value.as_typed_data.values = | 310 object->value.as_typed_data.values = |
| 311 buffer->value.as_typed_data.values + | 311 buffer->value.as_typed_data.values + |
| 312 object->internal.as_view.offset_in_bytes; | 312 object->internal.as_view.offset_in_bytes; |
| 313 } else { | 313 } else { |
| 314 // TODO(sgjesse): Handle other instances. Currently this will | 314 // TODO(sgjesse): Handle other instances. Currently this will |
| 315 // skew the reading as the fields of the instance is not read. | 315 // skew the reading as the fields of the instance is not read. |
| 316 } | 316 } |
| 317 return object; | 317 return object; |
| 318 } | 318 } |
| 319 | 319 |
| 320 ASSERT((class_header & kSmiTagMask) != 0); | 320 ASSERT((class_header & kSmiTagMask) != 0); |
| 321 class_id = LookupInternalClass(class_header); | 321 class_id = LookupInternalClass(class_header); |
| 322 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { | 322 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { |
| 323 intptr_t len = ReadSmiValue(); | 323 intptr_t len = ReadSmiValue(); |
| 324 Dart_CObject* value = GetBackRef(object_id); | 324 Dart_CObject* value = GetBackRef(object_id); |
| 325 if (value == NULL) { | 325 if (value == NULL) { |
| 326 value = AllocateDartCObjectArray(len); | 326 value = AllocateDartCObjectArray(len); |
| 327 AddBackRef(object_id, value, kIsDeserialized); | 327 AddBackRef(object_id, value, kIsDeserialized); |
| 328 } | 328 } |
| 329 // Skip type arguments. | 329 // Skip type arguments. |
| 330 // TODO(sjesse): Remove this when message serialization format is | 330 // TODO(sjesse): Remove this when message serialization format is |
| 331 // updated (currently type_arguments is leaked). | 331 // updated (currently type_arguments is leaked). |
| 332 Dart_CObject* type_arguments = ReadObjectImpl(); | 332 Dart_CObject* type_arguments = ReadObjectImpl(); |
| 333 if (type_arguments != &type_arguments_marker && | 333 if (type_arguments != &type_arguments_marker && |
| 334 type_arguments->type != Dart_CObject::kNull) { | 334 type_arguments->type != Dart_CObject_kNull) { |
| 335 return AllocateDartCObjectUnsupported(); | 335 return AllocateDartCObjectUnsupported(); |
| 336 } | 336 } |
| 337 for (int i = 0; i < len; i++) { | 337 for (int i = 0; i < len; i++) { |
| 338 value->value.as_array.values[i] = ReadObjectRef(); | 338 value->value.as_array.values[i] = ReadObjectRef(); |
| 339 } | 339 } |
| 340 return value; | 340 return value; |
| 341 } | 341 } |
| 342 | 342 |
| 343 return ReadInternalVMObject(class_id, object_id); | 343 return ReadInternalVMObject(class_id, object_id); |
| 344 } | 344 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Reading of regular dart instances has limited support in order to | 398 // Reading of regular dart instances has limited support in order to |
| 399 // read typed data views. | 399 // read typed data views. |
| 400 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { | 400 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { |
| 401 intptr_t object_id = SerializedHeaderData::decode(value); | 401 intptr_t object_id = SerializedHeaderData::decode(value); |
| 402 Dart_CObject_Internal* object = | 402 Dart_CObject_Internal* object = |
| 403 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); | 403 AllocateDartCObjectInternal(Dart_CObject_Internal::kUninitialized); |
| 404 AddBackRef(object_id, object, kIsNotDeserialized); | 404 AddBackRef(object_id, object, kIsNotDeserialized); |
| 405 // Read class of object. | 405 // Read class of object. |
| 406 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); | 406 object->cls = reinterpret_cast<Dart_CObject_Internal*>(ReadObjectImpl()); |
| 407 ASSERT(object->cls->type == | 407 ASSERT(object->cls->type == |
| 408 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kClass)); | 408 static_cast<Dart_CObject_Type>(Dart_CObject_Internal::kClass)); |
| 409 return object; | 409 return object; |
| 410 } | 410 } |
| 411 ASSERT((class_header & kSmiTagMask) != 0); | 411 ASSERT((class_header & kSmiTagMask) != 0); |
| 412 intptr_t object_id = SerializedHeaderData::decode(value); | 412 intptr_t object_id = SerializedHeaderData::decode(value); |
| 413 intptr_t class_id = LookupInternalClass(class_header); | 413 intptr_t class_id = LookupInternalClass(class_header); |
| 414 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { | 414 if ((class_id == kArrayCid) || (class_id == kImmutableArrayCid)) { |
| 415 ASSERT(GetBackRef(object_id) == NULL); | 415 ASSERT(GetBackRef(object_id) == NULL); |
| 416 intptr_t len = ReadSmiValue(); | 416 intptr_t len = ReadSmiValue(); |
| 417 Dart_CObject* value = AllocateDartCObjectArray(len); | 417 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 418 AddBackRef(object_id, value, kIsNotDeserialized); | 418 AddBackRef(object_id, value, kIsNotDeserialized); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 446 | 446 |
| 447 | 447 |
| 448 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, | 448 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, |
| 449 intptr_t object_id) { | 449 intptr_t object_id) { |
| 450 switch (class_id) { | 450 switch (class_id) { |
| 451 case kClassCid: { | 451 case kClassCid: { |
| 452 Dart_CObject_Internal* object = AllocateDartCObjectClass(); | 452 Dart_CObject_Internal* object = AllocateDartCObjectClass(); |
| 453 AddBackRef(object_id, object, kIsDeserialized); | 453 AddBackRef(object_id, object, kIsDeserialized); |
| 454 object->internal.as_class.library_url = ReadObjectImpl(); | 454 object->internal.as_class.library_url = ReadObjectImpl(); |
| 455 ASSERT(object->internal.as_class.library_url->type == | 455 ASSERT(object->internal.as_class.library_url->type == |
| 456 Dart_CObject::kString); | 456 Dart_CObject_kString); |
| 457 object->internal.as_class.class_name = ReadObjectImpl(); | 457 object->internal.as_class.class_name = ReadObjectImpl(); |
| 458 ASSERT(object->internal.as_class.class_name->type == | 458 ASSERT(object->internal.as_class.class_name->type == |
| 459 Dart_CObject::kString); | 459 Dart_CObject_kString); |
| 460 return object; | 460 return object; |
| 461 } | 461 } |
| 462 case kTypeArgumentsCid: { | 462 case kTypeArgumentsCid: { |
| 463 // TODO(sjesse): Remove this when message serialization format is | 463 // TODO(sjesse): Remove this when message serialization format is |
| 464 // updated (currently length is leaked). | 464 // updated (currently length is leaked). |
| 465 Dart_CObject* value = &type_arguments_marker; | 465 Dart_CObject* value = &type_arguments_marker; |
| 466 AddBackRef(object_id, value, kIsDeserialized); | 466 AddBackRef(object_id, value, kIsDeserialized); |
| 467 Dart_CObject* length = ReadObjectImpl(); | 467 Dart_CObject* length = ReadObjectImpl(); |
| 468 ASSERT(length->type == Dart_CObject::kInt32); | 468 ASSERT(length->type == Dart_CObject_kInt32); |
| 469 for (int i = 0; i < length->value.as_int32; i++) { | 469 for (int i = 0; i < length->value.as_int32; i++) { |
| 470 Dart_CObject* type = ReadObjectImpl(); | 470 Dart_CObject* type = ReadObjectImpl(); |
| 471 if (type != &dynamic_type_marker) { | 471 if (type != &dynamic_type_marker) { |
| 472 return AllocateDartCObjectUnsupported(); | 472 return AllocateDartCObjectUnsupported(); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 return value; | 475 return value; |
| 476 } | 476 } |
| 477 case kTypeParameterCid: { | 477 case kTypeParameterCid: { |
| 478 // TODO(sgjesse): Fix this workaround ignoring the type parameter. | 478 // TODO(sgjesse): Fix this workaround ignoring the type parameter. |
| 479 Dart_CObject* value = &dynamic_type_marker; | 479 Dart_CObject* value = &dynamic_type_marker; |
| 480 AddBackRef(object_id, value, kIsDeserialized); | 480 AddBackRef(object_id, value, kIsDeserialized); |
| 481 intptr_t index = ReadIntptrValue(); | 481 intptr_t index = ReadIntptrValue(); |
| 482 USE(index); | 482 USE(index); |
| 483 intptr_t token_index = ReadIntptrValue(); | 483 intptr_t token_index = ReadIntptrValue(); |
| 484 USE(token_index); | 484 USE(token_index); |
| 485 int8_t type_state = Read<int8_t>(); | 485 int8_t type_state = Read<int8_t>(); |
| 486 USE(type_state); | 486 USE(type_state); |
| 487 Dart_CObject* parameterized_class = ReadObjectImpl(); | 487 Dart_CObject* parameterized_class = ReadObjectImpl(); |
| 488 // The type parameter is finalized, therefore parameterized_class is null. | 488 // The type parameter is finalized, therefore parameterized_class is null. |
| 489 ASSERT(parameterized_class->type == Dart_CObject::kNull); | 489 ASSERT(parameterized_class->type == Dart_CObject_kNull); |
| 490 Dart_CObject* name = ReadObjectImpl(); | 490 Dart_CObject* name = ReadObjectImpl(); |
| 491 ASSERT(name->type == Dart_CObject::kString); | 491 ASSERT(name->type == Dart_CObject_kString); |
| 492 return value; | 492 return value; |
| 493 } | 493 } |
| 494 case kMintCid: { | 494 case kMintCid: { |
| 495 int64_t value = Read<int64_t>(); | 495 int64_t value = Read<int64_t>(); |
| 496 Dart_CObject* object; | 496 Dart_CObject* object; |
| 497 if (kMinInt32 <= value && value <= kMaxInt32) { | 497 if (kMinInt32 <= value && value <= kMaxInt32) { |
| 498 object = AllocateDartCObjectInt32(value); | 498 object = AllocateDartCObjectInt32(value); |
| 499 } else { | 499 } else { |
| 500 object = AllocateDartCObjectInt64(value); | 500 object = AllocateDartCObjectInt64(value); |
| 501 } | 501 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 *p = '\0'; | 575 *p = '\0'; |
| 576 ASSERT(p == (object->value.as_string + utf8_len)); | 576 ASSERT(p == (object->value.as_string + utf8_len)); |
| 577 ::free(utf16); | 577 ::free(utf16); |
| 578 return object; | 578 return object; |
| 579 } | 579 } |
| 580 | 580 |
| 581 #define READ_TYPED_DATA(type, ctype) \ | 581 #define READ_TYPED_DATA(type, ctype) \ |
| 582 { \ | 582 { \ |
| 583 intptr_t len = ReadSmiValue(); \ | 583 intptr_t len = ReadSmiValue(); \ |
| 584 Dart_CObject* object = \ | 584 Dart_CObject* object = \ |
| 585 AllocateDartCObjectTypedData(Dart_CObject::k##type##Array, len); \ | 585 AllocateDartCObjectTypedData(Dart_TypedData_k##type, len); \ |
| 586 AddBackRef(object_id, object, kIsDeserialized); \ | 586 AddBackRef(object_id, object, kIsDeserialized); \ |
| 587 if (len > 0) { \ | 587 if (len > 0) { \ |
| 588 ctype* p = \ | 588 ctype* p = \ |
| 589 reinterpret_cast<ctype*>(object->value.as_typed_data.values); \ | 589 reinterpret_cast<ctype*>(object->value.as_typed_data.values); \ |
| 590 for (intptr_t i = 0; i < len; i++) { \ | 590 for (intptr_t i = 0; i < len; i++) { \ |
| 591 p[i] = Read<ctype>(); \ | 591 p[i] = Read<ctype>(); \ |
| 592 } \ | 592 } \ |
| 593 } \ | 593 } \ |
| 594 return object; \ | 594 return object; \ |
| 595 } \ | 595 } \ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 647 |
| 648 Dart_CObject* value = GetBackRef(object_id); | 648 Dart_CObject* value = GetBackRef(object_id); |
| 649 ASSERT(value == NULL); | 649 ASSERT(value == NULL); |
| 650 // Allocate an empty array for the GrowableObjectArray which | 650 // Allocate an empty array for the GrowableObjectArray which |
| 651 // will be updated to point to the content when the backing | 651 // will be updated to point to the content when the backing |
| 652 // store has been deserialized. | 652 // store has been deserialized. |
| 653 value = AllocateDartCObjectArray(0); | 653 value = AllocateDartCObjectArray(0); |
| 654 AddBackRef(object_id, value, kIsDeserialized); | 654 AddBackRef(object_id, value, kIsDeserialized); |
| 655 // Read the content of the GrowableObjectArray. | 655 // Read the content of the GrowableObjectArray. |
| 656 Dart_CObject* content = ReadObjectImpl(); | 656 Dart_CObject* content = ReadObjectImpl(); |
| 657 ASSERT(content->type == Dart_CObject::kArray); | 657 ASSERT(content->type == Dart_CObject_kArray); |
| 658 // Make the empty array allocated point to the backing store content. | 658 // Make the empty array allocated point to the backing store content. |
| 659 value->value.as_array.length = len; | 659 value->value.as_array.length = len; |
| 660 value->value.as_array.values = content->value.as_array.values; | 660 value->value.as_array.values = content->value.as_array.values; |
| 661 return value; | 661 return value; |
| 662 } | 662 } |
| 663 default: | 663 default: |
| 664 // Everything else not supported. | 664 // Everything else not supported. |
| 665 Dart_CObject* value = AllocateDartCObjectUnsupported(); | 665 Dart_CObject* value = AllocateDartCObjectUnsupported(); |
| 666 AddBackRef(object_id, value, kIsDeserialized); | 666 AddBackRef(object_id, value, kIsDeserialized); |
| 667 return value; | 667 return value; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 } | 760 } |
| 761 } | 761 } |
| 762 | 762 |
| 763 | 763 |
| 764 void ApiMessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) { | 764 void ApiMessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) { |
| 765 // Mark the object as serialized by adding the object id to the | 765 // Mark the object as serialized by adding the object id to the |
| 766 // upper bits of the type field in the Dart_CObject structure. Add | 766 // upper bits of the type field in the Dart_CObject structure. Add |
| 767 // an offset for making marking of object id 0 possible. | 767 // an offset for making marking of object id 0 possible. |
| 768 ASSERT(!IsCObjectMarked(object)); | 768 ASSERT(!IsCObjectMarked(object)); |
| 769 intptr_t mark_value = object_id + kDartCObjectMarkOffset; | 769 intptr_t mark_value = object_id + kDartCObjectMarkOffset; |
| 770 object->type = static_cast<Dart_CObject::Type>( | 770 object->type = static_cast<Dart_CObject_Type>( |
| 771 ((mark_value) << kDartCObjectTypeBits) | object->type); | 771 ((mark_value) << kDartCObjectTypeBits) | object->type); |
| 772 } | 772 } |
| 773 | 773 |
| 774 | 774 |
| 775 void ApiMessageWriter::UnmarkCObject(Dart_CObject* object) { | 775 void ApiMessageWriter::UnmarkCObject(Dart_CObject* object) { |
| 776 ASSERT(IsCObjectMarked(object)); | 776 ASSERT(IsCObjectMarked(object)); |
| 777 object->type = static_cast<Dart_CObject::Type>( | 777 object->type = static_cast<Dart_CObject_Type>( |
| 778 object->type & kDartCObjectTypeMask); | 778 object->type & kDartCObjectTypeMask); |
| 779 } | 779 } |
| 780 | 780 |
| 781 | 781 |
| 782 bool ApiMessageWriter::IsCObjectMarked(Dart_CObject* object) { | 782 bool ApiMessageWriter::IsCObjectMarked(Dart_CObject* object) { |
| 783 return (object->type & kDartCObjectMarkMask) != 0; | 783 return (object->type & kDartCObjectMarkMask) != 0; |
| 784 } | 784 } |
| 785 | 785 |
| 786 | 786 |
| 787 intptr_t ApiMessageWriter::GetMarkedCObjectMark(Dart_CObject* object) { | 787 intptr_t ApiMessageWriter::GetMarkedCObjectMark(Dart_CObject* object) { |
| 788 ASSERT(IsCObjectMarked(object)); | 788 ASSERT(IsCObjectMarked(object)); |
| 789 intptr_t mark_value = | 789 intptr_t mark_value = |
| 790 ((object->type & kDartCObjectMarkMask) >> kDartCObjectTypeBits); | 790 ((object->type & kDartCObjectMarkMask) >> kDartCObjectTypeBits); |
| 791 // An offset was added to object id for making marking object id 0 possible. | 791 // An offset was added to object id for making marking object id 0 possible. |
| 792 return mark_value - kDartCObjectMarkOffset; | 792 return mark_value - kDartCObjectMarkOffset; |
| 793 } | 793 } |
| 794 | 794 |
| 795 | 795 |
| 796 void ApiMessageWriter::UnmarkAllCObjects(Dart_CObject* object) { | 796 void ApiMessageWriter::UnmarkAllCObjects(Dart_CObject* object) { |
| 797 if (!IsCObjectMarked(object)) return; | 797 if (!IsCObjectMarked(object)) return; |
| 798 UnmarkCObject(object); | 798 UnmarkCObject(object); |
| 799 if (object->type == Dart_CObject::kArray) { | 799 if (object->type == Dart_CObject_kArray) { |
| 800 for (int i = 0; i < object->value.as_array.length; i++) { | 800 for (int i = 0; i < object->value.as_array.length; i++) { |
| 801 Dart_CObject* element = object->value.as_array.values[i]; | 801 Dart_CObject* element = object->value.as_array.values[i]; |
| 802 UnmarkAllCObjects(element); | 802 UnmarkAllCObjects(element); |
| 803 } | 803 } |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 | 806 |
| 807 | 807 |
| 808 void ApiMessageWriter::AddToForwardList(Dart_CObject* object) { | 808 void ApiMessageWriter::AddToForwardList(Dart_CObject* object) { |
| 809 if (forward_id_ >= forward_list_length_) { | 809 if (forward_id_ >= forward_list_length_) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 } | 878 } |
| 879 | 879 |
| 880 | 880 |
| 881 bool ApiMessageWriter::WriteCObject(Dart_CObject* object) { | 881 bool ApiMessageWriter::WriteCObject(Dart_CObject* object) { |
| 882 if (IsCObjectMarked(object)) { | 882 if (IsCObjectMarked(object)) { |
| 883 intptr_t object_id = GetMarkedCObjectMark(object); | 883 intptr_t object_id = GetMarkedCObjectMark(object); |
| 884 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | 884 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); |
| 885 return true; | 885 return true; |
| 886 } | 886 } |
| 887 | 887 |
| 888 Dart_CObject::Type type = object->type; | 888 Dart_CObject_Type type = object->type; |
| 889 if (type == Dart_CObject::kArray) { | 889 if (type == Dart_CObject_kArray) { |
| 890 // Write out the serialization header value for this object. | 890 // Write out the serialization header value for this object. |
| 891 WriteInlinedHeader(object); | 891 WriteInlinedHeader(object); |
| 892 // Write out the class and tags information. | 892 // Write out the class and tags information. |
| 893 WriteIndexedObject(kArrayCid); | 893 WriteIndexedObject(kArrayCid); |
| 894 WriteIntptrValue(0); | 894 WriteIntptrValue(0); |
| 895 | 895 |
| 896 WriteSmi(object->value.as_array.length); | 896 WriteSmi(object->value.as_array.length); |
| 897 // Write out the type arguments. | 897 // Write out the type arguments. |
| 898 WriteNullObject(); | 898 WriteNullObject(); |
| 899 // Write out array elements. | 899 // Write out array elements. |
| 900 for (int i = 0; i < object->value.as_array.length; i++) { | 900 for (int i = 0; i < object->value.as_array.length; i++) { |
| 901 bool success = WriteCObjectRef(object->value.as_array.values[i]); | 901 bool success = WriteCObjectRef(object->value.as_array.values[i]); |
| 902 if (!success) return false; | 902 if (!success) return false; |
| 903 } | 903 } |
| 904 return true; | 904 return true; |
| 905 } | 905 } |
| 906 return WriteCObjectInlined(object, type); | 906 return WriteCObjectInlined(object, type); |
| 907 } | 907 } |
| 908 | 908 |
| 909 | 909 |
| 910 bool ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { | 910 bool ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { |
| 911 if (IsCObjectMarked(object)) { | 911 if (IsCObjectMarked(object)) { |
| 912 intptr_t object_id = GetMarkedCObjectMark(object); | 912 intptr_t object_id = GetMarkedCObjectMark(object); |
| 913 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | 913 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); |
| 914 return true; | 914 return true; |
| 915 } | 915 } |
| 916 | 916 |
| 917 Dart_CObject::Type type = object->type; | 917 Dart_CObject_Type type = object->type; |
| 918 if (type == Dart_CObject::kArray) { | 918 if (type == Dart_CObject_kArray) { |
| 919 // Write out the serialization header value for this object. | 919 // Write out the serialization header value for this object. |
| 920 WriteInlinedHeader(object); | 920 WriteInlinedHeader(object); |
| 921 // Write out the class information. | 921 // Write out the class information. |
| 922 WriteIndexedObject(kArrayCid); | 922 WriteIndexedObject(kArrayCid); |
| 923 // Write out the length information. | 923 // Write out the length information. |
| 924 WriteSmi(object->value.as_array.length); | 924 WriteSmi(object->value.as_array.length); |
| 925 // Add object to forward list so that this object is serialized later. | 925 // Add object to forward list so that this object is serialized later. |
| 926 AddToForwardList(object); | 926 AddToForwardList(object); |
| 927 return true; | 927 return true; |
| 928 } | 928 } |
| 929 return WriteCObjectInlined(object, type); | 929 return WriteCObjectInlined(object, type); |
| 930 } | 930 } |
| 931 | 931 |
| 932 | 932 |
| 933 bool ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { | 933 bool ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { |
| 934 ASSERT(IsCObjectMarked(object)); | 934 ASSERT(IsCObjectMarked(object)); |
| 935 Dart_CObject::Type type = | 935 Dart_CObject_Type type = |
| 936 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); | 936 static_cast<Dart_CObject_Type>(object->type & kDartCObjectTypeMask); |
| 937 ASSERT(type == Dart_CObject::kArray); | 937 ASSERT(type == Dart_CObject_kArray); |
| 938 | 938 |
| 939 // Write out the serialization header value for this object. | 939 // Write out the serialization header value for this object. |
| 940 intptr_t object_id = GetMarkedCObjectMark(object); | 940 intptr_t object_id = GetMarkedCObjectMark(object); |
| 941 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); | 941 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id); |
| 942 // Write out the class and tags information. | 942 // Write out the class and tags information. |
| 943 WriteIndexedObject(kArrayCid); | 943 WriteIndexedObject(kArrayCid); |
| 944 WriteIntptrValue(0); | 944 WriteIntptrValue(0); |
| 945 | 945 |
| 946 WriteSmi(object->value.as_array.length); | 946 WriteSmi(object->value.as_array.length); |
| 947 // Write out the type arguments. | 947 // Write out the type arguments. |
| 948 WriteNullObject(); | 948 WriteNullObject(); |
| 949 // Write out array elements. | 949 // Write out array elements. |
| 950 for (int i = 0; i < object->value.as_array.length; i++) { | 950 for (int i = 0; i < object->value.as_array.length; i++) { |
| 951 bool success = WriteCObjectRef(object->value.as_array.values[i]); | 951 bool success = WriteCObjectRef(object->value.as_array.values[i]); |
| 952 if (!success) return false; | 952 if (!success) return false; |
| 953 } | 953 } |
| 954 return true; | 954 return true; |
| 955 } | 955 } |
| 956 | 956 |
| 957 | 957 |
| 958 bool ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, | 958 bool ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, |
| 959 Dart_CObject::Type type) { | 959 Dart_CObject_Type type) { |
| 960 switch (type) { | 960 switch (type) { |
| 961 case Dart_CObject::kNull: | 961 case Dart_CObject_kNull: |
| 962 WriteNullObject(); | 962 WriteNullObject(); |
| 963 break; | 963 break; |
| 964 case Dart_CObject::kBool: | 964 case Dart_CObject_kBool: |
| 965 if (object->value.as_bool) { | 965 if (object->value.as_bool) { |
| 966 WriteVMIsolateObject(kTrueValue); | 966 WriteVMIsolateObject(kTrueValue); |
| 967 } else { | 967 } else { |
| 968 WriteVMIsolateObject(kFalseValue); | 968 WriteVMIsolateObject(kFalseValue); |
| 969 } | 969 } |
| 970 break; | 970 break; |
| 971 case Dart_CObject::kInt32: | 971 case Dart_CObject_kInt32: |
| 972 WriteInt32(object); | 972 WriteInt32(object); |
| 973 break; | 973 break; |
| 974 case Dart_CObject::kInt64: | 974 case Dart_CObject_kInt64: |
| 975 WriteInt64(object); | 975 WriteInt64(object); |
| 976 break; | 976 break; |
| 977 case Dart_CObject::kBigint: { | 977 case Dart_CObject_kBigint: { |
| 978 // Write out the serialization header value for this object. | 978 // Write out the serialization header value for this object. |
| 979 WriteInlinedHeader(object); | 979 WriteInlinedHeader(object); |
| 980 // Write out the class and tags information. | 980 // Write out the class and tags information. |
| 981 WriteIndexedObject(kBigintCid); | 981 WriteIndexedObject(kBigintCid); |
| 982 WriteIntptrValue(0); | 982 WriteIntptrValue(0); |
| 983 // Write hex string length and content | 983 // Write hex string length and content |
| 984 char* hex_string = object->value.as_bigint; | 984 char* hex_string = object->value.as_bigint; |
| 985 intptr_t len = strlen(hex_string); | 985 intptr_t len = strlen(hex_string); |
| 986 WriteIntptrValue(len); | 986 WriteIntptrValue(len); |
| 987 for (intptr_t i = 0; i < len; i++) { | 987 for (intptr_t i = 0; i < len; i++) { |
| 988 Write<uint8_t>(hex_string[i]); | 988 Write<uint8_t>(hex_string[i]); |
| 989 } | 989 } |
| 990 break; | 990 break; |
| 991 } | 991 } |
| 992 case Dart_CObject::kDouble: | 992 case Dart_CObject_kDouble: |
| 993 // Write out the serialization header value for this object. | 993 // Write out the serialization header value for this object. |
| 994 WriteInlinedHeader(object); | 994 WriteInlinedHeader(object); |
| 995 // Write out the class and tags information. | 995 // Write out the class and tags information. |
| 996 WriteIndexedObject(kDoubleCid); | 996 WriteIndexedObject(kDoubleCid); |
| 997 WriteIntptrValue(0); | 997 WriteIntptrValue(0); |
| 998 // Write double value. | 998 // Write double value. |
| 999 Write<double>(object->value.as_double); | 999 Write<double>(object->value.as_double); |
| 1000 break; | 1000 break; |
| 1001 case Dart_CObject::kString: { | 1001 case Dart_CObject_kString: { |
| 1002 const uint8_t* utf8_str = | 1002 const uint8_t* utf8_str = |
| 1003 reinterpret_cast<const uint8_t*>(object->value.as_string); | 1003 reinterpret_cast<const uint8_t*>(object->value.as_string); |
| 1004 intptr_t utf8_len = strlen(object->value.as_string); | 1004 intptr_t utf8_len = strlen(object->value.as_string); |
| 1005 if (!Utf8::IsValid(utf8_str, utf8_len)) { | 1005 if (!Utf8::IsValid(utf8_str, utf8_len)) { |
| 1006 return false; | 1006 return false; |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 Utf8::Type type; | 1009 Utf8::Type type; |
| 1010 intptr_t len = Utf8::CodeUnitCount(utf8_str, utf8_len, &type); | 1010 intptr_t len = Utf8::CodeUnitCount(utf8_str, utf8_len, &type); |
| 1011 | 1011 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1035 reinterpret_cast<uint16_t*>(::malloc(len * sizeof(uint16_t))); | 1035 reinterpret_cast<uint16_t*>(::malloc(len * sizeof(uint16_t))); |
| 1036 bool success = Utf8::DecodeToUTF16(utf8_str, utf8_len, utf16_str, len); | 1036 bool success = Utf8::DecodeToUTF16(utf8_str, utf8_len, utf16_str, len); |
| 1037 ASSERT(success); | 1037 ASSERT(success); |
| 1038 for (intptr_t i = 0; i < len; i++) { | 1038 for (intptr_t i = 0; i < len; i++) { |
| 1039 Write<uint16_t>(utf16_str[i]); | 1039 Write<uint16_t>(utf16_str[i]); |
| 1040 } | 1040 } |
| 1041 ::free(utf16_str); | 1041 ::free(utf16_str); |
| 1042 } | 1042 } |
| 1043 break; | 1043 break; |
| 1044 } | 1044 } |
| 1045 case Dart_CObject::kTypedData: { | 1045 case Dart_CObject_kTypedData: { |
| 1046 // Write out the serialization header value for this object. | 1046 // Write out the serialization header value for this object. |
| 1047 WriteInlinedHeader(object); | 1047 WriteInlinedHeader(object); |
| 1048 // Write out the class and tags information. | 1048 // Write out the class and tags information. |
| 1049 intptr_t class_id; | 1049 intptr_t class_id; |
| 1050 switch (object->value.as_typed_data.type) { | 1050 switch (object->value.as_typed_data.type) { |
| 1051 case Dart_CObject::kInt8Array: | 1051 case Dart_TypedData_kInt8: |
| 1052 class_id = kTypedDataInt8ArrayCid; | 1052 class_id = kTypedDataInt8ArrayCid; |
| 1053 break; | 1053 break; |
| 1054 case Dart_CObject::kUint8Array: | 1054 case Dart_TypedData_kUint8: |
| 1055 class_id = kTypedDataUint8ArrayCid; | 1055 class_id = kTypedDataUint8ArrayCid; |
| 1056 break; | 1056 break; |
| 1057 default: | 1057 default: |
| 1058 class_id = kTypedDataUint8ArrayCid; | 1058 class_id = kTypedDataUint8ArrayCid; |
| 1059 UNIMPLEMENTED(); | 1059 UNIMPLEMENTED(); |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 WriteIndexedObject(class_id); | 1062 WriteIndexedObject(class_id); |
| 1063 WriteIntptrValue(RawObject::ClassIdTag::update(class_id, 0)); | 1063 WriteIntptrValue(RawObject::ClassIdTag::update(class_id, 0)); |
| 1064 uint8_t* bytes = object->value.as_typed_data.values; | 1064 uint8_t* bytes = object->value.as_typed_data.values; |
| 1065 intptr_t len = object->value.as_typed_data.length; | 1065 intptr_t len = object->value.as_typed_data.length; |
| 1066 WriteSmi(len); | 1066 WriteSmi(len); |
| 1067 for (intptr_t i = 0; i < len; i++) { | 1067 for (intptr_t i = 0; i < len; i++) { |
| 1068 Write<uint8_t>(bytes[i]); | 1068 Write<uint8_t>(bytes[i]); |
| 1069 } | 1069 } |
| 1070 break; | 1070 break; |
| 1071 } | 1071 } |
| 1072 case Dart_CObject::kExternalTypedData: { | 1072 case Dart_CObject_kExternalTypedData: { |
| 1073 // TODO(ager): we are writing C pointers into the message in | 1073 // TODO(ager): we are writing C pointers into the message in |
| 1074 // order to post external arrays through ports. We need to make | 1074 // order to post external arrays through ports. We need to make |
| 1075 // sure that messages containing pointers can never be posted | 1075 // sure that messages containing pointers can never be posted |
| 1076 // to other processes. | 1076 // to other processes. |
| 1077 | 1077 |
| 1078 // Write out serialization header value for this object. | 1078 // Write out serialization header value for this object. |
| 1079 WriteInlinedHeader(object); | 1079 WriteInlinedHeader(object); |
| 1080 // Write out the class and tag information. | 1080 // Write out the class and tag information. |
| 1081 WriteIndexedObject(kExternalTypedDataUint8ArrayCid); | 1081 WriteIndexedObject(kExternalTypedDataUint8ArrayCid); |
| 1082 WriteIntptrValue(RawObject::ClassIdTag::update( | 1082 WriteIntptrValue(RawObject::ClassIdTag::update( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 if (!success) { | 1114 if (!success) { |
| 1115 UnmarkAllCObjects(object); | 1115 UnmarkAllCObjects(object); |
| 1116 return false; | 1116 return false; |
| 1117 } | 1117 } |
| 1118 } | 1118 } |
| 1119 UnmarkAllCObjects(object); | 1119 UnmarkAllCObjects(object); |
| 1120 return true; | 1120 return true; |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 } // namespace dart | 1123 } // namespace dart |
| OLD | NEW |