| 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 #ifndef RUNTIME_VM_DART_API_MESSAGE_H_ | 5 #ifndef RUNTIME_VM_DART_API_MESSAGE_H_ |
| 6 #define RUNTIME_VM_DART_API_MESSAGE_H_ | 6 #define RUNTIME_VM_DART_API_MESSAGE_H_ |
| 7 | 7 |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "platform/utils.h" | 9 #include "platform/utils.h" |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 | 44 |
| 45 // Reads a message snapshot into a C structure. | 45 // Reads a message snapshot into a C structure. |
| 46 class ApiMessageReader : public BaseReader { | 46 class ApiMessageReader : public BaseReader { |
| 47 public: | 47 public: |
| 48 // The ApiMessageReader object must be enclosed by an ApiNativeScope. | 48 // The ApiMessageReader object must be enclosed by an ApiNativeScope. |
| 49 // Allocation of all C Heap objects is done in the zone associated with | 49 // Allocation of all C Heap objects is done in the zone associated with |
| 50 // the enclosing ApiNativeScope. | 50 // the enclosing ApiNativeScope. |
| 51 ApiMessageReader(const uint8_t* buffer, intptr_t length); | 51 ApiMessageReader(const uint8_t* buffer, intptr_t length); |
| 52 explicit ApiMessageReader(Message* message); | 52 explicit ApiMessageReader(Message* message); |
| 53 ~ApiMessageReader() { } | 53 ~ApiMessageReader() {} |
| 54 | 54 |
| 55 Dart_CObject* ReadMessage(); | 55 Dart_CObject* ReadMessage(); |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 class BackRefNode { | 58 class BackRefNode { |
| 59 public: | 59 public: |
| 60 BackRefNode(Dart_CObject* reference, DeserializeState state) | 60 BackRefNode(Dart_CObject* reference, DeserializeState state) |
| 61 : reference_(reference), state_(state) {} | 61 : reference_(reference), state_(state) {} |
| 62 Dart_CObject* reference() const { return reference_; } | 62 Dart_CObject* reference() const { return reference_; } |
| 63 void set_reference(Dart_CObject* reference) { reference_ = reference; } | 63 void set_reference(Dart_CObject* reference) { reference_ = reference; } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 Dart_CObject* AllocateDartCObjectInt32(int32_t value); | 86 Dart_CObject* AllocateDartCObjectInt32(int32_t value); |
| 87 // Allocates a Dart_CObject object for for a 64-bit integer. | 87 // Allocates a Dart_CObject object for for a 64-bit integer. |
| 88 Dart_CObject* AllocateDartCObjectInt64(int64_t value); | 88 Dart_CObject* AllocateDartCObjectInt64(int64_t value); |
| 89 // Allocates an empty Dart_CObject object for a bigint to be filled up later. | 89 // Allocates an empty Dart_CObject object for a bigint to be filled up later. |
| 90 Dart_CObject* AllocateDartCObjectBigint(); | 90 Dart_CObject* AllocateDartCObjectBigint(); |
| 91 // Allocates a Dart_CObject object for a double. | 91 // Allocates a Dart_CObject object for a double. |
| 92 Dart_CObject* AllocateDartCObjectDouble(double value); | 92 Dart_CObject* AllocateDartCObjectDouble(double value); |
| 93 // Allocates a Dart_CObject object for string data. | 93 // Allocates a Dart_CObject object for string data. |
| 94 Dart_CObject* AllocateDartCObjectString(intptr_t length); | 94 Dart_CObject* AllocateDartCObjectString(intptr_t length); |
| 95 // Allocates a C Dart_CObject object for a typed data. | 95 // Allocates a C Dart_CObject object for a typed data. |
| 96 Dart_CObject* AllocateDartCObjectTypedData( | 96 Dart_CObject* AllocateDartCObjectTypedData(Dart_TypedData_Type type, |
| 97 Dart_TypedData_Type type, intptr_t length); | 97 intptr_t length); |
| 98 // Allocates a C array of Dart_CObject objects. | 98 // Allocates a C array of Dart_CObject objects. |
| 99 Dart_CObject* AllocateDartCObjectArray(intptr_t length); | 99 Dart_CObject* AllocateDartCObjectArray(intptr_t length); |
| 100 // Allocate a C Dart_CObject object for a VM isolate object. | 100 // Allocate a C Dart_CObject object for a VM isolate object. |
| 101 Dart_CObject* AllocateDartCObjectVmIsolateObj(intptr_t id); | 101 Dart_CObject* AllocateDartCObjectVmIsolateObj(intptr_t id); |
| 102 // Allocates a Dart_CObject_Internal object with the specified type. | 102 // Allocates a Dart_CObject_Internal object with the specified type. |
| 103 Dart_CObject_Internal* AllocateDartCObjectInternal( | 103 Dart_CObject_Internal* AllocateDartCObjectInternal( |
| 104 Dart_CObject_Internal::Type type); | 104 Dart_CObject_Internal::Type type); |
| 105 // Allocates a Dart_CObject_Internal object for a class object. | 105 // Allocates a Dart_CObject_Internal object for a class object. |
| 106 Dart_CObject_Internal* AllocateDartCObjectClass(); | 106 Dart_CObject_Internal* AllocateDartCObjectClass(); |
| 107 // Allocates a backwards reference node. | 107 // Allocates a backwards reference node. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 130 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { | 130 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { |
| 131 ASSERT(object->type >= Dart_CObject_kNumberOfTypes); | 131 ASSERT(object->type >= Dart_CObject_kNumberOfTypes); |
| 132 return reinterpret_cast<Dart_CObject_Internal*>(object); | 132 return reinterpret_cast<Dart_CObject_Internal*>(object); |
| 133 } | 133 } |
| 134 | 134 |
| 135 RawObject* VmIsolateSnapshotObject(intptr_t index) const { | 135 RawObject* VmIsolateSnapshotObject(intptr_t index) const { |
| 136 return Object::vm_isolate_snapshot_object_table().At(index); | 136 return Object::vm_isolate_snapshot_object_table().At(index); |
| 137 } | 137 } |
| 138 | 138 |
| 139 Dart_CObject* CreateDartCObjectString(RawObject* raw); | 139 Dart_CObject* CreateDartCObjectString(RawObject* raw); |
| 140 Dart_CObject* GetCanonicalMintObject(Dart_CObject_Type type, | 140 Dart_CObject* GetCanonicalMintObject(Dart_CObject_Type type, int64_t value64); |
| 141 int64_t value64); | |
| 142 | 141 |
| 143 uint8_t* allocator(intptr_t size) { | 142 uint8_t* allocator(intptr_t size) { |
| 144 return zone_->Realloc<uint8_t>(NULL, 0, size); | 143 return zone_->Realloc<uint8_t>(NULL, 0, size); |
| 145 } | 144 } |
| 146 | 145 |
| 147 Zone* zone_; // Zone in which C heap objects are allocated. | 146 Zone* zone_; // Zone in which C heap objects are allocated. |
| 148 ApiGrowableArray<BackRefNode*> backward_references_; | 147 ApiGrowableArray<BackRefNode*> backward_references_; |
| 149 ApiGrowableArray<Dart_CObject*> vm_isolate_references_; | 148 ApiGrowableArray<Dart_CObject*> vm_isolate_references_; |
| 150 Dart_CObject** vm_symbol_references_; | 149 Dart_CObject** vm_symbol_references_; |
| 151 | 150 |
| 152 Dart_CObject type_arguments_marker; | 151 Dart_CObject type_arguments_marker; |
| 153 Dart_CObject dynamic_type_marker; | 152 Dart_CObject dynamic_type_marker; |
| 154 static _Dart_CObject* singleton_uint32_typed_data_; | 153 static _Dart_CObject* singleton_uint32_typed_data_; |
| 155 }; | 154 }; |
| 156 | 155 |
| 157 | 156 |
| 158 class ApiMessageWriter : public BaseWriter { | 157 class ApiMessageWriter : public BaseWriter { |
| 159 public: | 158 public: |
| 160 static const intptr_t kInitialSize = 512; | 159 static const intptr_t kInitialSize = 512; |
| 161 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) | 160 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) |
| 162 : BaseWriter(buffer, alloc, kInitialSize), | 161 : BaseWriter(buffer, alloc, kInitialSize), |
| 163 object_id_(0), forward_list_(NULL), | 162 object_id_(0), |
| 164 forward_list_length_(0), forward_id_(0) { | 163 forward_list_(NULL), |
| 164 forward_list_length_(0), |
| 165 forward_id_(0) { |
| 165 ASSERT(kDartCObjectTypeMask >= Dart_CObject_kNumberOfTypes - 1); | 166 ASSERT(kDartCObjectTypeMask >= Dart_CObject_kNumberOfTypes - 1); |
| 166 } | 167 } |
| 167 ~ApiMessageWriter() { | 168 ~ApiMessageWriter() { ::free(forward_list_); } |
| 168 ::free(forward_list_); | |
| 169 } | |
| 170 | 169 |
| 171 // Writes a message of integers. | 170 // Writes a message of integers. |
| 172 void WriteMessage(intptr_t field_count, intptr_t *data); | 171 void WriteMessage(intptr_t field_count, intptr_t* data); |
| 173 | 172 |
| 174 // Writes a message with a single object. | 173 // Writes a message with a single object. |
| 175 bool WriteCMessage(Dart_CObject* object); | 174 bool WriteCMessage(Dart_CObject* object); |
| 176 | 175 |
| 177 private: | 176 private: |
| 178 static const intptr_t kDartCObjectTypeBits = 4; | 177 static const intptr_t kDartCObjectTypeBits = 4; |
| 179 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; | 178 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; |
| 180 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; | 179 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; |
| 181 static const intptr_t kDartCObjectMarkOffset = 1; | 180 static const intptr_t kDartCObjectMarkOffset = 1; |
| 182 | 181 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 243 |
| 245 static void ConvertNull(Dart_CObject* c_obj) { | 244 static void ConvertNull(Dart_CObject* c_obj) { |
| 246 c_obj->type = Dart_CObject_kNull; | 245 c_obj->type = Dart_CObject_kNull; |
| 247 c_obj->value.as_int64 = 0; | 246 c_obj->value.as_int64 = 0; |
| 248 } | 247 } |
| 249 }; | 248 }; |
| 250 | 249 |
| 251 } // namespace dart | 250 } // namespace dart |
| 252 | 251 |
| 253 #endif // RUNTIME_VM_DART_API_MESSAGE_H_ | 252 #endif // RUNTIME_VM_DART_API_MESSAGE_H_ |
| OLD | NEW |