Chromium Code Reviews| 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 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 static const int kNumInitialReferences = 4; | 13 static const int kNumInitialReferences = 4; |
| 14 | 14 |
| 15 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, | 15 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, |
| 16 intptr_t length, | 16 intptr_t length, |
| 17 ReAlloc alloc) | 17 ReAlloc alloc) |
| 18 : BaseReader(buffer, length), | 18 : BaseReader(buffer, length), |
| 19 alloc_(alloc), | 19 alloc_(alloc), |
| 20 backward_references_(kNumInitialReferences) { | 20 backward_references_(kNumInitialReferences), |
| 21 vm_symbol_references_(NULL) { | |
| 21 Init(); | 22 Init(); |
| 22 } | 23 } |
| 23 | 24 |
| 24 | 25 |
| 25 void ApiMessageReader::Init() { | 26 void ApiMessageReader::Init() { |
| 26 // Initialize marker objects used to handle Lists. | 27 // Initialize marker objects used to handle Lists. |
| 27 // TODO(sjesse): Remove this when message serialization format is | 28 // TODO(sjesse): Remove this when message serialization format is |
| 28 // updated. | 29 // updated. |
| 29 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); | 30 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); |
| 30 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); | 31 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 209 } |
| 209 return value; | 210 return value; |
| 210 } | 211 } |
| 211 | 212 |
| 212 return ReadInternalVMObject(class_id, object_id); | 213 return ReadInternalVMObject(class_id, object_id); |
| 213 } | 214 } |
| 214 | 215 |
| 215 | 216 |
| 216 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { | 217 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { |
| 217 if (Symbols::IsVMSymbolId(object_id)) { | 218 if (Symbols::IsVMSymbolId(object_id)) { |
| 219 intptr_t symbol_id = object_id - kMaxPredefinedObjectIds; | |
| 220 Dart_CObject* object; | |
| 221 if (vm_symbol_references_ != NULL && | |
| 222 (object = vm_symbol_references_[symbol_id]) != NULL) { | |
| 223 return object; | |
| 224 } | |
| 225 | |
| 226 if (vm_symbol_references_ == NULL) { | |
| 227 intptr_t size = sizeof(*vm_symbol_references_) * Symbols::kMaxId; | |
| 228 vm_symbol_references_ = | |
| 229 reinterpret_cast<Dart_CObject**>(alloc_(NULL, 0, size)); | |
| 230 #ifdef DEBUG | |
|
Florian Schneider
2012/11/19 14:30:08
I think you need to zero-initialize this array in
Søren Gjesse
2012/11/19 14:54:47
Absolutely, thanks for spotting.
| |
| 231 memset(vm_symbol_references_, 0, size); | |
| 232 #endif | |
| 233 } | |
| 234 | |
| 218 RawOneByteString* str = | 235 RawOneByteString* str = |
| 219 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id)); | 236 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id)); |
| 220 intptr_t len = Smi::Value(str->ptr()->length_); | 237 intptr_t len = Smi::Value(str->ptr()->length_); |
| 221 Dart_CObject* object = AllocateDartCObjectString(len); | 238 object = AllocateDartCObjectString(len); |
| 222 char* p = object->value.as_string; | 239 char* p = object->value.as_string; |
| 223 memmove(p, str->ptr()->data_, len); | 240 memmove(p, str->ptr()->data_, len); |
| 224 p[len] = '\0'; | 241 p[len] = '\0'; |
| 242 ASSERT(vm_symbol_references_[symbol_id] == NULL); | |
| 243 vm_symbol_references_[symbol_id] = object; | |
| 225 return object; | 244 return object; |
| 226 } | 245 } |
| 227 // No other VM isolate objects are supported. | 246 // No other VM isolate objects are supported. |
| 228 return AllocateDartCObjectNull(); | 247 return AllocateDartCObjectNull(); |
| 229 } | 248 } |
| 230 | 249 |
| 231 | 250 |
| 232 Dart_CObject* ApiMessageReader::ReadObjectRef() { | 251 Dart_CObject* ApiMessageReader::ReadObjectRef() { |
| 233 int64_t value = Read<int64_t>(); | 252 int64_t value = Read<int64_t>(); |
| 234 if ((value & kSmiTagMask) == 0) { | 253 if ((value & kSmiTagMask) == 0) { |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 if (!success) { | 884 if (!success) { |
| 866 UnmarkAllCObjects(object); | 885 UnmarkAllCObjects(object); |
| 867 return false; | 886 return false; |
| 868 } | 887 } |
| 869 } | 888 } |
| 870 UnmarkAllCObjects(object); | 889 UnmarkAllCObjects(object); |
| 871 return true; | 890 return true; |
| 872 } | 891 } |
| 873 | 892 |
| 874 } // namespace dart | 893 } // namespace dart |
| OLD | NEW |