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_SNAPSHOT_H_ | 5 #ifndef VM_SNAPSHOT_H_ |
6 #define VM_SNAPSHOT_H_ | 6 #define VM_SNAPSHOT_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 class RawTokenStream; | 49 class RawTokenStream; |
50 class RawType; | 50 class RawType; |
51 class RawTypeParameter; | 51 class RawTypeParameter; |
52 class RawTypeArguments; | 52 class RawTypeArguments; |
53 class RawTwoByteString; | 53 class RawTwoByteString; |
54 class RawUnresolvedClass; | 54 class RawUnresolvedClass; |
55 class String; | 55 class String; |
56 | 56 |
57 // Serialized object header encoding is as follows: | 57 // Serialized object header encoding is as follows: |
58 // - Smi: the Smi value is written as is (last bit is not tagged). | 58 // - Smi: the Smi value is written as is (last bit is not tagged). |
59 // - VM internal type (from VM isolate): (index of type in vm isolate | 0x3) | 59 // - VM object (from VM isolate): (object id in vm isolate | 0x3) |
60 // - Object that has already been written: (negative id in stream | 0x3) | 60 // This valus is serialized as a negative number. |
61 // (note VM objects are never serialized they are expected to be found | |
62 // using ths unique ID assigned to them). | |
63 // - Reference to object that has already been written: (object id | 0x3) | |
64 // This valus is serialized as a positive number. | |
61 // - Object that is seen for the first time (inlined in the stream): | 65 // - Object that is seen for the first time (inlined in the stream): |
62 // (a unique id for this object | 0x1) | 66 // (a unique id for this object | 0x1) |
63 enum SerializedHeaderType { | 67 enum SerializedHeaderType { |
Ivan Posva
2012/08/03 00:26:50
Vertical white space?
siva
2012/08/06 21:20:56
Done.
| |
64 kInlined = 0x1, | 68 kInlined = 0x1, |
65 kObjectId = 0x3, | 69 kObjectId = 0x3, |
66 }; | 70 }; |
67 static const int8_t kHeaderTagBits = 2; | 71 static const int8_t kHeaderTagBits = 2; |
68 static const int8_t kObjectIdTagBits = (kBitsPerWord - kHeaderTagBits); | 72 static const int8_t kObjectIdBits = (kBitsPerWord - (kHeaderTagBits + 1)); |
69 static const intptr_t kMaxObjectId = (kIntptrMax >> kHeaderTagBits); | 73 static const intptr_t kMaxObjectId = (kUwordMax >> (kHeaderTagBits + 1)); |
70 | |
71 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, | 74 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, |
72 0, | 75 0, |
73 kHeaderTagBits> { | 76 kHeaderTagBits> { |
74 }; | 77 }; |
75 | |
76 | |
77 class SerializedHeaderData : public BitField<intptr_t, | 78 class SerializedHeaderData : public BitField<intptr_t, |
78 kHeaderTagBits, | 79 kHeaderTagBits, |
79 kObjectIdTagBits> { | 80 kObjectIdBits> { |
80 }; | 81 }; |
81 | 82 |
82 | |
83 enum DeserializeState { | 83 enum DeserializeState { |
84 kIsDeserialized = 0, | 84 kIsDeserialized = 0, |
85 kIsNotDeserialized = 1, | 85 kIsNotDeserialized = 1, |
86 }; | 86 }; |
87 | 87 |
88 | |
89 enum SerializeState { | 88 enum SerializeState { |
90 kIsSerialized = 0, | 89 kIsSerialized = 0, |
91 kIsNotSerialized = 1, | 90 kIsNotSerialized = 1, |
92 }; | 91 }; |
93 | 92 |
94 | 93 |
95 // Structure capturing the raw snapshot. | 94 // Structure capturing the raw snapshot. |
96 class Snapshot { | 95 class Snapshot { |
97 public: | 96 public: |
98 enum Kind { | 97 enum Kind { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 return value; | 150 return value; |
152 } | 151 } |
153 | 152 |
154 void ReadBytes(uint8_t* addr, intptr_t len) { | 153 void ReadBytes(uint8_t* addr, intptr_t len) { |
155 stream_.ReadBytes(addr, len); | 154 stream_.ReadBytes(addr, len); |
156 } | 155 } |
157 | 156 |
158 RawSmi* ReadAsSmi(); | 157 RawSmi* ReadAsSmi(); |
159 intptr_t ReadSmiValue(); | 158 intptr_t ReadSmiValue(); |
160 | 159 |
160 // Negative header value indicates VM isolate object id. | |
161 bool IsVMIsolateObject(intptr_t header_value) { return (header_value < 0); } | |
162 intptr_t GetVMIsolateObjectId(intptr_t header_val) { | |
163 ASSERT(IsVMIsolateObject(header_val)); | |
164 intptr_t value = -header_val; // Header is negative for VM isolate objects. | |
165 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); | |
166 return SerializedHeaderData::decode(value); | |
167 } | |
168 | |
161 private: | 169 private: |
162 ReadStream stream_; // input stream. | 170 ReadStream stream_; // input stream. |
163 }; | 171 }; |
164 | 172 |
165 | 173 |
166 // Reads a snapshot into objects. | 174 // Reads a snapshot into objects. |
167 class SnapshotReader : public BaseReader { | 175 class SnapshotReader : public BaseReader { |
168 public: | 176 public: |
169 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); | 177 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); |
170 ~SnapshotReader() { } | 178 ~SnapshotReader() { } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 }; | 242 }; |
235 | 243 |
236 // Allocate uninitialized objects, this is used when reading a full snapshot. | 244 // Allocate uninitialized objects, this is used when reading a full snapshot. |
237 RawObject* AllocateUninitialized(const Class& cls, intptr_t size); | 245 RawObject* AllocateUninitialized(const Class& cls, intptr_t size); |
238 | 246 |
239 RawClass* ReadClassId(intptr_t object_id); | 247 RawClass* ReadClassId(intptr_t object_id); |
240 RawObject* ReadObjectImpl(); | 248 RawObject* ReadObjectImpl(); |
241 RawObject* ReadObjectImpl(intptr_t header); | 249 RawObject* ReadObjectImpl(intptr_t header); |
242 RawObject* ReadObjectRef(); | 250 RawObject* ReadObjectRef(); |
243 | 251 |
244 // Read an object that was serialized as an Id (singleton, object store, | 252 // Read a VM isolate object that was serialized as an Id. |
253 RawObject* ReadVMIsolateObject(intptr_t object_id); | |
254 | |
255 // Read an object that was serialized as an Id (singleton in object store, | |
245 // or an object that was already serialized before). | 256 // or an object that was already serialized before). |
246 RawObject* ReadIndexedObject(intptr_t object_id); | 257 RawObject* ReadIndexedObject(intptr_t object_id); |
247 | 258 |
248 // Read an inlined object from the stream. | 259 // Read an inlined object from the stream. |
249 RawObject* ReadInlinedObject(intptr_t object_id); | 260 RawObject* ReadInlinedObject(intptr_t object_id); |
250 | 261 |
251 // Based on header field check to see if it is an internal VM class. | 262 // Based on header field check to see if it is an internal VM class. |
252 RawClass* LookupInternalClass(intptr_t class_header); | 263 RawClass* LookupInternalClass(intptr_t class_header); |
253 | 264 |
254 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); | 265 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 template <typename T> | 308 template <typename T> |
298 void Write(T value) { | 309 void Write(T value) { |
299 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 310 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
300 } | 311 } |
301 | 312 |
302 // Writes an intptr_t type value out. | 313 // Writes an intptr_t type value out. |
303 void WriteIntptrValue(intptr_t value) { | 314 void WriteIntptrValue(intptr_t value) { |
304 Write<int64_t>(value); | 315 Write<int64_t>(value); |
305 } | 316 } |
306 | 317 |
307 // Write an object that is serialized as an Id (singleton, object store, | 318 // Write an object that is serialized as an Id (singleton in object store, |
308 // or an object that was already serialized before). | 319 // or an object that was already serialized before). |
309 void WriteIndexedObject(intptr_t object_id) { | 320 void WriteIndexedObject(intptr_t object_id) { |
310 WriteSerializationMarker(kObjectId, object_id); | 321 ASSERT(object_id <= kMaxObjectId); |
322 intptr_t value = 0; | |
323 value = SerializedHeaderTag::update(kObjectId, value); | |
324 value = SerializedHeaderData::update(object_id, value); | |
325 WriteIntptrValue(value); | |
311 } | 326 } |
312 | 327 |
313 // Write out object header value. | 328 // Write a VM Isolateobject that is serialized as an Id. |
314 void WriteObjectHeader(intptr_t class_id, intptr_t tags) { | 329 void WriteVMIsolateObject(intptr_t object_id) { |
315 // Write out the class information. | 330 ASSERT(object_id <= kMaxObjectId); |
316 WriteIndexedObject(class_id); | 331 intptr_t value = 0; |
317 // Write out the tags information. | 332 value = SerializedHeaderTag::update(kObjectId, value); |
318 WriteIntptrValue(tags); | 333 value = SerializedHeaderData::update(object_id, value); |
334 WriteIntptrValue(-value); // Write as a negative value. | |
319 } | 335 } |
320 | 336 |
321 // Write serialization header information for an object. | 337 // Write serialization header information for an object. |
322 void WriteSerializationMarker(SerializedHeaderType type, intptr_t id) { | 338 void WriteInlinedObjectHeader(intptr_t id) { |
323 ASSERT(id <= kMaxObjectId); | 339 ASSERT(id <= kMaxObjectId); |
324 intptr_t value = 0; | 340 intptr_t value = 0; |
325 value = SerializedHeaderTag::update(type, value); | 341 value = SerializedHeaderTag::update(kInlined, value); |
326 value = SerializedHeaderData::update(id, value); | 342 value = SerializedHeaderData::update(id, value); |
327 WriteIntptrValue(value); | 343 WriteIntptrValue(value); |
328 } | 344 } |
329 | 345 |
330 // Write out a buffer of bytes. | 346 // Write out a buffer of bytes. |
331 void WriteBytes(const uint8_t* addr, intptr_t len) { | 347 void WriteBytes(const uint8_t* addr, intptr_t len) { |
332 stream_.WriteBytes(addr, len); | 348 stream_.WriteBytes(addr, len); |
333 } | 349 } |
334 | 350 |
335 // Finalize the serialized buffer by filling in the header information | 351 // Finalize the serialized buffer by filling in the header information |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 uword tags_; | 418 uword tags_; |
403 SerializeState state_; | 419 SerializeState state_; |
404 | 420 |
405 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode); | 421 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode); |
406 }; | 422 }; |
407 | 423 |
408 intptr_t MarkObject(RawObject* raw, SerializeState state); | 424 intptr_t MarkObject(RawObject* raw, SerializeState state); |
409 void UnmarkAll(); | 425 void UnmarkAll(); |
410 | 426 |
411 bool CheckAndWritePredefinedObject(RawObject* raw); | 427 bool CheckAndWritePredefinedObject(RawObject* raw); |
428 void HandleVMIsolateObject(RawObject* raw); | |
412 | 429 |
413 void WriteObjectRef(RawObject* raw); | 430 void WriteObjectRef(RawObject* raw); |
414 void WriteClassId(RawClass* cls); | 431 void WriteClassId(RawClass* cls); |
415 void WriteObjectImpl(RawObject* raw); | 432 void WriteObjectImpl(RawObject* raw); |
416 void WriteInlinedObject(RawObject* raw); | 433 void WriteInlinedObject(RawObject* raw); |
417 void WriteForwardedObjects(); | 434 void WriteForwardedObjects(); |
418 void ArrayWriteTo(intptr_t object_id, | 435 void ArrayWriteTo(intptr_t object_id, |
419 intptr_t array_kind, | 436 intptr_t array_kind, |
420 intptr_t tags, | 437 intptr_t tags, |
421 RawSmi* length, | 438 RawSmi* length, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 private: | 497 private: |
481 SnapshotWriter* writer_; | 498 SnapshotWriter* writer_; |
482 bool as_references_; | 499 bool as_references_; |
483 | 500 |
484 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 501 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
485 }; | 502 }; |
486 | 503 |
487 } // namespace dart | 504 } // namespace dart |
488 | 505 |
489 #endif // VM_SNAPSHOT_H_ | 506 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |