| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/assert.h" | 9 #include "vm/assert.h" |
| 10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 SnapshotWriter(Snapshot::Kind kind, uint8_t** buffer, ReAlloc alloc) | 391 SnapshotWriter(Snapshot::Kind kind, uint8_t** buffer, ReAlloc alloc) |
| 392 : stream_(buffer, alloc), | 392 : stream_(buffer, alloc), |
| 393 kind_(kind), | 393 kind_(kind), |
| 394 object_store_(Isolate::Current()->object_store()), | 394 object_store_(Isolate::Current()->object_store()), |
| 395 forward_list_() { | 395 forward_list_() { |
| 396 ASSERT(buffer != NULL); | 396 ASSERT(buffer != NULL); |
| 397 ASSERT(alloc != NULL); | 397 ASSERT(alloc != NULL); |
| 398 } | 398 } |
| 399 ~SnapshotWriter() { } | 399 ~SnapshotWriter() { } |
| 400 | 400 |
| 401 // Snapshot kind. |
| 402 Snapshot::Kind kind() const { return kind_; } |
| 403 |
| 401 // Size of the snapshot. | 404 // Size of the snapshot. |
| 402 intptr_t Size() const { return stream_.bytes_written(); } | 405 intptr_t Size() const { return stream_.bytes_written(); } |
| 403 | 406 |
| 404 // Finalize the serialized buffer by filling in the header information | 407 // Finalize the serialized buffer by filling in the header information |
| 405 // which comprises of a flag(full/partial snaphot) and the length of | 408 // which comprises of a flag(full/partial snaphot) and the length of |
| 406 // serialzed bytes. | 409 // serialzed bytes. |
| 407 void FinalizeBuffer() { | 410 void FinalizeBuffer() { |
| 408 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer()); | 411 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer()); |
| 409 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 412 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
| 410 data[Snapshot::kSnapshotFlagIndex] = kind_; | 413 data[Snapshot::kSnapshotFlagIndex] = kind_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 Snapshot::Kind kind_; | 478 Snapshot::Kind kind_; |
| 476 ObjectStore* object_store_; // Object store for common classes. | 479 ObjectStore* object_store_; // Object store for common classes. |
| 477 GrowableArray<ForwardObjectNode*> forward_list_; | 480 GrowableArray<ForwardObjectNode*> forward_list_; |
| 478 | 481 |
| 479 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); | 482 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); |
| 480 }; | 483 }; |
| 481 | 484 |
| 482 | 485 |
| 483 class ScriptSnapshotWriter : public SnapshotWriter { | 486 class ScriptSnapshotWriter : public SnapshotWriter { |
| 484 public: | 487 public: |
| 485 ScriptSnapshotWriter(const Library& lib, uint8_t** buffer, ReAlloc alloc) | 488 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
| 486 : SnapshotWriter(Snapshot::kScript, buffer, alloc) { | 489 : SnapshotWriter(Snapshot::kScript, buffer, alloc) { |
| 487 ASSERT(buffer != NULL); | 490 ASSERT(buffer != NULL); |
| 488 ASSERT(alloc != NULL); | 491 ASSERT(alloc != NULL); |
| 489 } | 492 } |
| 490 ~ScriptSnapshotWriter() { } | 493 ~ScriptSnapshotWriter() { } |
| 491 | 494 |
| 492 // Writes a partial snapshot of the script. | 495 // Writes a partial snapshot of the script. |
| 493 void WriteScriptSnapshot(); | 496 void WriteScriptSnapshot(const Library& lib); |
| 494 | 497 |
| 495 private: | 498 private: |
| 496 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); | 499 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); |
| 497 }; | 500 }; |
| 498 | 501 |
| 499 | 502 |
| 500 // An object pointer visitor implementation which writes out | 503 // An object pointer visitor implementation which writes out |
| 501 // objects to a snap shot. | 504 // objects to a snap shot. |
| 502 class SnapshotWriterVisitor : public ObjectPointerVisitor { | 505 class SnapshotWriterVisitor : public ObjectPointerVisitor { |
| 503 public: | 506 public: |
| 504 explicit SnapshotWriterVisitor(SnapshotWriter* writer) : writer_(writer) {} | 507 explicit SnapshotWriterVisitor(SnapshotWriter* writer) : writer_(writer) {} |
| 505 | 508 |
| 506 virtual void VisitPointers(RawObject** first, RawObject** last); | 509 virtual void VisitPointers(RawObject** first, RawObject** last); |
| 507 | 510 |
| 508 private: | 511 private: |
| 509 SnapshotWriter* writer_; | 512 SnapshotWriter* writer_; |
| 510 | 513 |
| 511 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 514 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 512 }; | 515 }; |
| 513 | 516 |
| 514 } // namespace dart | 517 } // namespace dart |
| 515 | 518 |
| 516 #endif // VM_SNAPSHOT_H_ | 519 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |