| 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 { |
| 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)); |
| 74 |
| 70 | 75 |
| 71 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, | 76 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, |
| 72 0, | 77 0, |
| 73 kHeaderTagBits> { | 78 kHeaderTagBits> { |
| 74 }; | 79 }; |
| 75 | 80 |
| 76 | 81 |
| 77 class SerializedHeaderData : public BitField<intptr_t, | 82 class SerializedHeaderData : public BitField<intptr_t, |
| 78 kHeaderTagBits, | 83 kHeaderTagBits, |
| 79 kObjectIdTagBits> { | 84 kObjectIdBits> { |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 | 87 |
| 83 enum DeserializeState { | 88 enum DeserializeState { |
| 84 kIsDeserialized = 0, | 89 kIsDeserialized = 0, |
| 85 kIsNotDeserialized = 1, | 90 kIsNotDeserialized = 1, |
| 86 }; | 91 }; |
| 87 | 92 |
| 88 | 93 |
| 89 enum SerializeState { | 94 enum SerializeState { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return value; | 156 return value; |
| 152 } | 157 } |
| 153 | 158 |
| 154 void ReadBytes(uint8_t* addr, intptr_t len) { | 159 void ReadBytes(uint8_t* addr, intptr_t len) { |
| 155 stream_.ReadBytes(addr, len); | 160 stream_.ReadBytes(addr, len); |
| 156 } | 161 } |
| 157 | 162 |
| 158 RawSmi* ReadAsSmi(); | 163 RawSmi* ReadAsSmi(); |
| 159 intptr_t ReadSmiValue(); | 164 intptr_t ReadSmiValue(); |
| 160 | 165 |
| 166 // Negative header value indicates VM isolate object id. |
| 167 bool IsVMIsolateObject(intptr_t header_value) { return (header_value < 0); } |
| 168 intptr_t GetVMIsolateObjectId(intptr_t header_val) { |
| 169 ASSERT(IsVMIsolateObject(header_val)); |
| 170 intptr_t value = -header_val; // Header is negative for VM isolate objects. |
| 171 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); |
| 172 return SerializedHeaderData::decode(value); |
| 173 } |
| 174 |
| 161 private: | 175 private: |
| 162 ReadStream stream_; // input stream. | 176 ReadStream stream_; // input stream. |
| 163 }; | 177 }; |
| 164 | 178 |
| 165 | 179 |
| 166 // Reads a snapshot into objects. | 180 // Reads a snapshot into objects. |
| 167 class SnapshotReader : public BaseReader { | 181 class SnapshotReader : public BaseReader { |
| 168 public: | 182 public: |
| 169 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); | 183 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); |
| 170 ~SnapshotReader() { } | 184 ~SnapshotReader() { } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 }; | 248 }; |
| 235 | 249 |
| 236 // Allocate uninitialized objects, this is used when reading a full snapshot. | 250 // Allocate uninitialized objects, this is used when reading a full snapshot. |
| 237 RawObject* AllocateUninitialized(const Class& cls, intptr_t size); | 251 RawObject* AllocateUninitialized(const Class& cls, intptr_t size); |
| 238 | 252 |
| 239 RawClass* ReadClassId(intptr_t object_id); | 253 RawClass* ReadClassId(intptr_t object_id); |
| 240 RawObject* ReadObjectImpl(); | 254 RawObject* ReadObjectImpl(); |
| 241 RawObject* ReadObjectImpl(intptr_t header); | 255 RawObject* ReadObjectImpl(intptr_t header); |
| 242 RawObject* ReadObjectRef(); | 256 RawObject* ReadObjectRef(); |
| 243 | 257 |
| 244 // Read an object that was serialized as an Id (singleton, object store, | 258 // Read a VM isolate object that was serialized as an Id. |
| 259 RawObject* ReadVMIsolateObject(intptr_t object_id); |
| 260 |
| 261 // Read an object that was serialized as an Id (singleton in object store, |
| 245 // or an object that was already serialized before). | 262 // or an object that was already serialized before). |
| 246 RawObject* ReadIndexedObject(intptr_t object_id); | 263 RawObject* ReadIndexedObject(intptr_t object_id); |
| 247 | 264 |
| 248 // Read an inlined object from the stream. | 265 // Read an inlined object from the stream. |
| 249 RawObject* ReadInlinedObject(intptr_t object_id); | 266 RawObject* ReadInlinedObject(intptr_t object_id); |
| 250 | 267 |
| 251 // Based on header field check to see if it is an internal VM class. | 268 // Based on header field check to see if it is an internal VM class. |
| 252 RawClass* LookupInternalClass(intptr_t class_header); | 269 RawClass* LookupInternalClass(intptr_t class_header); |
| 253 | 270 |
| 254 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); | 271 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> | 314 template <typename T> |
| 298 void Write(T value) { | 315 void Write(T value) { |
| 299 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 316 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| 300 } | 317 } |
| 301 | 318 |
| 302 // Writes an intptr_t type value out. | 319 // Writes an intptr_t type value out. |
| 303 void WriteIntptrValue(intptr_t value) { | 320 void WriteIntptrValue(intptr_t value) { |
| 304 Write<int64_t>(value); | 321 Write<int64_t>(value); |
| 305 } | 322 } |
| 306 | 323 |
| 307 // Write an object that is serialized as an Id (singleton, object store, | 324 // Write an object that is serialized as an Id (singleton in object store, |
| 308 // or an object that was already serialized before). | 325 // or an object that was already serialized before). |
| 309 void WriteIndexedObject(intptr_t object_id) { | 326 void WriteIndexedObject(intptr_t object_id) { |
| 310 WriteSerializationMarker(kObjectId, object_id); | 327 ASSERT(object_id <= kMaxObjectId); |
| 328 intptr_t value = 0; |
| 329 value = SerializedHeaderTag::update(kObjectId, value); |
| 330 value = SerializedHeaderData::update(object_id, value); |
| 331 WriteIntptrValue(value); |
| 311 } | 332 } |
| 312 | 333 |
| 313 // Write out object header value. | 334 // Write a VM Isolateobject that is serialized as an Id. |
| 314 void WriteObjectHeader(intptr_t class_id, intptr_t tags) { | 335 void WriteVMIsolateObject(intptr_t object_id) { |
| 315 // Write out the class information. | 336 ASSERT(object_id <= kMaxObjectId); |
| 316 WriteIndexedObject(class_id); | 337 intptr_t value = 0; |
| 317 // Write out the tags information. | 338 value = SerializedHeaderTag::update(kObjectId, value); |
| 318 WriteIntptrValue(tags); | 339 value = SerializedHeaderData::update(object_id, value); |
| 340 WriteIntptrValue(-value); // Write as a negative value. |
| 319 } | 341 } |
| 320 | 342 |
| 321 // Write serialization header information for an object. | 343 // Write serialization header information for an object. |
| 322 void WriteSerializationMarker(SerializedHeaderType type, intptr_t id) { | 344 void WriteInlinedObjectHeader(intptr_t id) { |
| 323 ASSERT(id <= kMaxObjectId); | 345 ASSERT(id <= kMaxObjectId); |
| 324 intptr_t value = 0; | 346 intptr_t value = 0; |
| 325 value = SerializedHeaderTag::update(type, value); | 347 value = SerializedHeaderTag::update(kInlined, value); |
| 326 value = SerializedHeaderData::update(id, value); | 348 value = SerializedHeaderData::update(id, value); |
| 327 WriteIntptrValue(value); | 349 WriteIntptrValue(value); |
| 328 } | 350 } |
| 329 | 351 |
| 330 // Write out a buffer of bytes. | 352 // Write out a buffer of bytes. |
| 331 void WriteBytes(const uint8_t* addr, intptr_t len) { | 353 void WriteBytes(const uint8_t* addr, intptr_t len) { |
| 332 stream_.WriteBytes(addr, len); | 354 stream_.WriteBytes(addr, len); |
| 333 } | 355 } |
| 334 | 356 |
| 335 // Finalize the serialized buffer by filling in the header information | 357 // 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_; | 424 uword tags_; |
| 403 SerializeState state_; | 425 SerializeState state_; |
| 404 | 426 |
| 405 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode); | 427 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode); |
| 406 }; | 428 }; |
| 407 | 429 |
| 408 intptr_t MarkObject(RawObject* raw, SerializeState state); | 430 intptr_t MarkObject(RawObject* raw, SerializeState state); |
| 409 void UnmarkAll(); | 431 void UnmarkAll(); |
| 410 | 432 |
| 411 bool CheckAndWritePredefinedObject(RawObject* raw); | 433 bool CheckAndWritePredefinedObject(RawObject* raw); |
| 434 void HandleVMIsolateObject(RawObject* raw); |
| 412 | 435 |
| 413 void WriteObjectRef(RawObject* raw); | 436 void WriteObjectRef(RawObject* raw); |
| 414 void WriteClassId(RawClass* cls); | 437 void WriteClassId(RawClass* cls); |
| 415 void WriteObjectImpl(RawObject* raw); | 438 void WriteObjectImpl(RawObject* raw); |
| 416 void WriteInlinedObject(RawObject* raw); | 439 void WriteInlinedObject(RawObject* raw); |
| 417 void WriteForwardedObjects(); | 440 void WriteForwardedObjects(); |
| 418 void ArrayWriteTo(intptr_t object_id, | 441 void ArrayWriteTo(intptr_t object_id, |
| 419 intptr_t array_kind, | 442 intptr_t array_kind, |
| 420 intptr_t tags, | 443 intptr_t tags, |
| 421 RawSmi* length, | 444 RawSmi* length, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 private: | 503 private: |
| 481 SnapshotWriter* writer_; | 504 SnapshotWriter* writer_; |
| 482 bool as_references_; | 505 bool as_references_; |
| 483 | 506 |
| 484 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 507 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 485 }; | 508 }; |
| 486 | 509 |
| 487 } // namespace dart | 510 } // namespace dart |
| 488 | 511 |
| 489 #endif // VM_SNAPSHOT_H_ | 512 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |