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 VM_DART_API_MESSAGE_H_ | 5 #ifndef VM_DART_API_MESSAGE_H_ |
6 #define VM_DART_API_MESSAGE_H_ | 6 #define VM_DART_API_MESSAGE_H_ |
7 | 7 |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/snapshot.h" | 9 #include "vm/snapshot.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 // Reads a message snapshot into a C structure. | 27 // Reads a message snapshot into a C structure. |
28 class ApiMessageReader : public BaseReader { | 28 class ApiMessageReader : public BaseReader { |
29 public: | 29 public: |
30 ApiMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); | 30 ApiMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); |
31 ~ApiMessageReader() { } | 31 ~ApiMessageReader() { } |
32 | 32 |
33 Dart_CObject* ReadMessage(); | 33 Dart_CObject* ReadMessage(); |
34 | 34 |
35 private: | 35 private: |
| 36 class BackRefNode { |
| 37 public: |
| 38 BackRefNode(Dart_CObject* reference, DeserializeState state) |
| 39 : reference_(reference), state_(state) {} |
| 40 Dart_CObject* reference() const { return reference_; } |
| 41 void set_reference(Dart_CObject* reference) { reference_ = reference; } |
| 42 bool is_deserialized() const { return state_ == kIsDeserialized; } |
| 43 void set_state(DeserializeState value) { state_ = value; } |
| 44 |
| 45 private: |
| 46 Dart_CObject* reference_; |
| 47 DeserializeState state_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(BackRefNode); |
| 50 }; |
| 51 |
36 // Allocates a Dart_CObject object. | 52 // Allocates a Dart_CObject object. |
37 Dart_CObject* AllocateDartCObject(); | 53 Dart_CObject* AllocateDartCObject(); |
38 // Allocates a Dart_CObject object with the specified type. | 54 // Allocates a Dart_CObject object with the specified type. |
39 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); | 55 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); |
40 // Allocates a Dart_CObject object representing an unsupported | 56 // Allocates a Dart_CObject object representing an unsupported |
41 // object in the API message. | 57 // object in the API message. |
42 Dart_CObject* AllocateDartCObjectUnsupported(); | 58 Dart_CObject* AllocateDartCObjectUnsupported(); |
43 // Allocates a Dart_CObject object for the null object. | 59 // Allocates a Dart_CObject object for the null object. |
44 Dart_CObject* AllocateDartCObjectNull(); | 60 Dart_CObject* AllocateDartCObjectNull(); |
45 // Allocates a Dart_CObject object for a boolean object. | 61 // Allocates a Dart_CObject object for a boolean object. |
46 Dart_CObject* AllocateDartCObjectBool(bool value); | 62 Dart_CObject* AllocateDartCObjectBool(bool value); |
47 // Allocates a Dart_CObject object for for a 32-bit integer. | 63 // Allocates a Dart_CObject object for for a 32-bit integer. |
48 Dart_CObject* AllocateDartCObjectInt32(int32_t value); | 64 Dart_CObject* AllocateDartCObjectInt32(int32_t value); |
49 // Allocates a Dart_CObject object for for a 64-bit integer. | 65 // Allocates a Dart_CObject object for for a 64-bit integer. |
50 Dart_CObject* AllocateDartCObjectInt64(int64_t value); | 66 Dart_CObject* AllocateDartCObjectInt64(int64_t value); |
51 // Allocates a Dart_CObject object for bigint data. | 67 // Allocates a Dart_CObject object for bigint data. |
52 Dart_CObject* AllocateDartCObjectBigint(intptr_t length); | 68 Dart_CObject* AllocateDartCObjectBigint(intptr_t length); |
53 // Allocates a Dart_CObject object for a double. | 69 // Allocates a Dart_CObject object for a double. |
54 Dart_CObject* AllocateDartCObjectDouble(double value); | 70 Dart_CObject* AllocateDartCObjectDouble(double value); |
55 // Allocates a Dart_CObject object for string data. | 71 // Allocates a Dart_CObject object for string data. |
56 Dart_CObject* AllocateDartCObjectString(intptr_t length); | 72 Dart_CObject* AllocateDartCObjectString(intptr_t length); |
57 // Allocates a C Dart_CObject object for byte data. | 73 // Allocates a C Dart_CObject object for byte data. |
58 Dart_CObject* AllocateDartCObjectUint8Array(intptr_t length); | 74 Dart_CObject* AllocateDartCObjectUint8Array(intptr_t length); |
59 // Allocates a C array of Dart_CObject objects. | 75 // Allocates a C array of Dart_CObject objects. |
60 Dart_CObject* AllocateDartCObjectArray(intptr_t length); | 76 Dart_CObject* AllocateDartCObjectArray(intptr_t length); |
| 77 // Allocates a backwards reference node. |
| 78 BackRefNode* AllocateBackRefNode(Dart_CObject* ref, DeserializeState state); |
61 | 79 |
62 void Init(); | 80 void Init(); |
63 | 81 |
64 intptr_t LookupInternalClass(intptr_t class_header); | 82 intptr_t LookupInternalClass(intptr_t class_header); |
| 83 Dart_CObject* ReadInternalVMObject(intptr_t class_id, intptr_t object_id); |
65 Dart_CObject* ReadInlinedObject(intptr_t object_id); | 84 Dart_CObject* ReadInlinedObject(intptr_t object_id); |
66 Dart_CObject* ReadObjectImpl(intptr_t header); | 85 Dart_CObject* ReadObjectImpl(); |
67 Dart_CObject* ReadIndexedObject(intptr_t object_id); | 86 Dart_CObject* ReadIndexedObject(intptr_t object_id); |
| 87 Dart_CObject* ReadObjectRef(); |
68 Dart_CObject* ReadObject(); | 88 Dart_CObject* ReadObject(); |
69 | 89 |
70 // Add object to backward references. | 90 // Add object to backward references. |
71 void AddBackwardReference(intptr_t id, Dart_CObject* obj); | 91 void AddBackRef(intptr_t id, Dart_CObject* obj, DeserializeState state); |
| 92 |
| 93 // Get an object from the backward references list. |
| 94 Dart_CObject* GetBackRef(intptr_t id); |
72 | 95 |
73 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { | 96 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { |
74 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); | 97 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); |
75 return reinterpret_cast<Dart_CObject_Internal*>(object); | 98 return reinterpret_cast<Dart_CObject_Internal*>(object); |
76 } | 99 } |
77 | 100 |
78 // Allocation of the structures for the decoded message happens | 101 // Allocation of the structures for the decoded message happens |
79 // either in the supplied zone or using the supplied allocation | 102 // either in the supplied zone or using the supplied allocation |
80 // function. | 103 // function. |
81 ReAlloc alloc_; | 104 ReAlloc alloc_; |
82 ApiGrowableArray<Dart_CObject*> backward_references_; | 105 ApiGrowableArray<BackRefNode*> backward_references_; |
83 | 106 |
84 Dart_CObject type_arguments_marker; | 107 Dart_CObject type_arguments_marker; |
85 Dart_CObject dynamic_type_marker; | 108 Dart_CObject dynamic_type_marker; |
86 }; | 109 }; |
87 | 110 |
88 | 111 |
89 class ApiMessageWriter : public BaseWriter { | 112 class ApiMessageWriter : public BaseWriter { |
90 public: | 113 public: |
91 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) | 114 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) |
92 : BaseWriter(buffer, alloc), object_id_(0) { | 115 : BaseWriter(buffer, alloc), object_id_(0), |
| 116 forward_list_(NULL), forward_list_length_(0), forward_id_(0) { |
93 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); | 117 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); |
94 } | 118 } |
95 ~ApiMessageWriter() { } | 119 ~ApiMessageWriter() { |
| 120 delete forward_list_; |
| 121 } |
96 | 122 |
97 // Writes a message of integers. | 123 // Writes a message of integers. |
98 void WriteMessage(intptr_t field_count, intptr_t *data); | 124 void WriteMessage(intptr_t field_count, intptr_t *data); |
99 | 125 |
100 void WriteCMessage(Dart_CObject* object); | 126 void WriteCMessage(Dart_CObject* object); |
101 | 127 |
102 void FinalizeBuffer() { | 128 void FinalizeBuffer() { |
103 BaseWriter::FinalizeBuffer(Snapshot::kMessage); | 129 BaseWriter::FinalizeBuffer(Snapshot::kMessage); |
104 } | 130 } |
105 | 131 |
106 private: | 132 private: |
107 static const intptr_t kDartCObjectTypeBits = 4; | 133 static const intptr_t kDartCObjectTypeBits = 4; |
108 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; | 134 static const intptr_t kDartCObjectTypeMask = (1 << kDartCObjectTypeBits) - 1; |
109 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; | 135 static const intptr_t kDartCObjectMarkMask = ~kDartCObjectTypeMask; |
110 static const intptr_t kDartCObjectMarkOffset = 1; | 136 static const intptr_t kDartCObjectMarkOffset = 1; |
111 | 137 |
112 void MarkCObject(Dart_CObject* object, intptr_t object_id); | 138 void MarkCObject(Dart_CObject* object, intptr_t object_id); |
113 void UnmarkCObject(Dart_CObject* object); | 139 void UnmarkCObject(Dart_CObject* object); |
114 bool IsCObjectMarked(Dart_CObject* object); | 140 bool IsCObjectMarked(Dart_CObject* object); |
115 intptr_t GetMarkedCObjectMark(Dart_CObject* object); | 141 intptr_t GetMarkedCObjectMark(Dart_CObject* object); |
116 void UnmarkAllCObjects(Dart_CObject* object); | 142 void UnmarkAllCObjects(Dart_CObject* object); |
| 143 void AddToForwardList(Dart_CObject* object); |
117 | 144 |
118 void WriteSmi(int64_t value); | 145 void WriteSmi(int64_t value); |
119 void WriteMint(Dart_CObject* object, int64_t value); | 146 void WriteMint(Dart_CObject* object, int64_t value); |
120 void WriteInt32(Dart_CObject* object); | 147 void WriteInt32(Dart_CObject* object); |
121 void WriteInt64(Dart_CObject* object); | 148 void WriteInt64(Dart_CObject* object); |
122 void WriteInlinedHeader(Dart_CObject* object); | 149 void WriteInlinedHeader(Dart_CObject* object); |
123 void WriteCObject(Dart_CObject* object); | 150 void WriteCObject(Dart_CObject* object); |
| 151 void WriteCObjectRef(Dart_CObject* object); |
| 152 void WriteForwardedCObject(Dart_CObject* object); |
| 153 void WriteCObjectInlined(Dart_CObject* object, Dart_CObject::Type type); |
124 | 154 |
125 intptr_t object_id_; | 155 intptr_t object_id_; |
| 156 Dart_CObject** forward_list_; |
| 157 intptr_t forward_list_length_; |
| 158 intptr_t forward_id_; |
126 | 159 |
127 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); | 160 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); |
128 }; | 161 }; |
129 | 162 |
130 } // namespace dart | 163 } // namespace dart |
131 | 164 |
132 #endif // VM_DART_API_MESSAGE_H_ | 165 #endif // VM_DART_API_MESSAGE_H_ |
OLD | NEW |