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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 value = SerializedHeaderData::update(id, value); | 381 value = SerializedHeaderData::update(id, value); |
382 WriteIntptrValue(value); | 382 WriteIntptrValue(value); |
383 } | 383 } |
384 | 384 |
385 // Write out a buffer of bytes. | 385 // Write out a buffer of bytes. |
386 void WriteBytes(const uint8_t* addr, intptr_t len) { | 386 void WriteBytes(const uint8_t* addr, intptr_t len) { |
387 stream_.WriteBytes(addr, len); | 387 stream_.WriteBytes(addr, len); |
388 } | 388 } |
389 | 389 |
390 protected: | 390 protected: |
391 BaseWriter(uint8_t** buffer, ReAlloc alloc) : stream_(buffer, alloc) { | 391 BaseWriter(uint8_t** buffer, |
| 392 ReAlloc alloc, |
| 393 intptr_t increment_size) : stream_(buffer, alloc, increment_size) { |
392 ASSERT(buffer != NULL); | 394 ASSERT(buffer != NULL); |
393 ASSERT(alloc != NULL); | 395 ASSERT(alloc != NULL); |
394 } | 396 } |
395 ~BaseWriter() { } | 397 ~BaseWriter() { } |
396 | 398 |
397 void ReserveHeader() { | 399 void ReserveHeader() { |
398 // Make room for recording snapshot buffer size. | 400 // Make room for recording snapshot buffer size. |
399 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); | 401 stream_.set_current(stream_.buffer() + Snapshot::kHeaderSize); |
400 } | 402 } |
401 | 403 |
402 void FillHeader(Snapshot::Kind kind) { | 404 void FillHeader(Snapshot::Kind kind) { |
403 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer()); | 405 int32_t* data = reinterpret_cast<int32_t*>(stream_.buffer()); |
404 data[Snapshot::kLengthIndex] = stream_.bytes_written(); | 406 data[Snapshot::kLengthIndex] = stream_.bytes_written(); |
405 data[Snapshot::kSnapshotFlagIndex] = kind; | 407 data[Snapshot::kSnapshotFlagIndex] = kind; |
406 } | 408 } |
407 | 409 |
408 private: | 410 private: |
409 WriteStream stream_; | 411 WriteStream stream_; |
410 | 412 |
411 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); | 413 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); |
412 }; | 414 }; |
413 | 415 |
414 | 416 |
415 class SnapshotWriter : public BaseWriter { | 417 class SnapshotWriter : public BaseWriter { |
416 protected: | 418 protected: |
417 SnapshotWriter(Snapshot::Kind kind, uint8_t** buffer, ReAlloc alloc) | 419 SnapshotWriter(Snapshot::Kind kind, |
418 : BaseWriter(buffer, alloc), | 420 uint8_t** buffer, |
| 421 ReAlloc alloc, |
| 422 intptr_t increment_size) |
| 423 : BaseWriter(buffer, alloc, increment_size), |
419 kind_(kind), | 424 kind_(kind), |
420 object_store_(Isolate::Current()->object_store()), | 425 object_store_(Isolate::Current()->object_store()), |
421 class_table_(Isolate::Current()->class_table()), | 426 class_table_(Isolate::Current()->class_table()), |
422 forward_list_() { | 427 forward_list_() { |
423 } | 428 } |
424 | 429 |
425 public: | 430 public: |
426 // Snapshot kind. | 431 // Snapshot kind. |
427 Snapshot::Kind kind() const { return kind_; } | 432 Snapshot::Kind kind() const { return kind_; } |
428 | 433 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 friend class RawScript; | 490 friend class RawScript; |
486 friend class RawTokenStream; | 491 friend class RawTokenStream; |
487 friend class RawTypeArguments; | 492 friend class RawTypeArguments; |
488 friend class SnapshotWriterVisitor; | 493 friend class SnapshotWriterVisitor; |
489 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); | 494 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); |
490 }; | 495 }; |
491 | 496 |
492 | 497 |
493 class FullSnapshotWriter : public SnapshotWriter { | 498 class FullSnapshotWriter : public SnapshotWriter { |
494 public: | 499 public: |
| 500 static const intptr_t kIncrementSize = 64 * KB; |
495 FullSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 501 FullSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
496 : SnapshotWriter(Snapshot::kFull, buffer, alloc) { | 502 : SnapshotWriter(Snapshot::kFull, buffer, alloc, kIncrementSize) { |
497 ASSERT(buffer != NULL); | 503 ASSERT(buffer != NULL); |
498 ASSERT(alloc != NULL); | 504 ASSERT(alloc != NULL); |
499 } | 505 } |
500 ~FullSnapshotWriter() { } | 506 ~FullSnapshotWriter() { } |
501 | 507 |
502 // Writes a full snapshot of the Isolate. | 508 // Writes a full snapshot of the Isolate. |
503 void WriteFullSnapshot(); | 509 void WriteFullSnapshot(); |
504 | 510 |
505 private: | 511 private: |
506 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); | 512 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); |
507 }; | 513 }; |
508 | 514 |
509 | 515 |
510 class ScriptSnapshotWriter : public SnapshotWriter { | 516 class ScriptSnapshotWriter : public SnapshotWriter { |
511 public: | 517 public: |
| 518 static const intptr_t kIncrementSize = 64 * KB; |
512 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 519 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
513 : SnapshotWriter(Snapshot::kScript, buffer, alloc) { | 520 : SnapshotWriter(Snapshot::kScript, buffer, alloc, kIncrementSize) { |
514 ASSERT(buffer != NULL); | 521 ASSERT(buffer != NULL); |
515 ASSERT(alloc != NULL); | 522 ASSERT(alloc != NULL); |
516 } | 523 } |
517 ~ScriptSnapshotWriter() { } | 524 ~ScriptSnapshotWriter() { } |
518 | 525 |
519 // Writes a partial snapshot of the script. | 526 // Writes a partial snapshot of the script. |
520 void WriteScriptSnapshot(const Library& lib); | 527 void WriteScriptSnapshot(const Library& lib); |
521 | 528 |
522 private: | 529 private: |
523 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); | 530 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); |
524 }; | 531 }; |
525 | 532 |
526 | 533 |
527 class MessageWriter : public SnapshotWriter { | 534 class MessageWriter : public SnapshotWriter { |
528 public: | 535 public: |
| 536 static const intptr_t kIncrementSize = 512; |
529 MessageWriter(uint8_t** buffer, ReAlloc alloc) | 537 MessageWriter(uint8_t** buffer, ReAlloc alloc) |
530 : SnapshotWriter(Snapshot::kMessage, buffer, alloc) { | 538 : SnapshotWriter(Snapshot::kMessage, buffer, alloc, kIncrementSize) { |
531 ASSERT(buffer != NULL); | 539 ASSERT(buffer != NULL); |
532 ASSERT(alloc != NULL); | 540 ASSERT(alloc != NULL); |
533 } | 541 } |
534 ~MessageWriter() { } | 542 ~MessageWriter() { } |
535 | 543 |
536 void WriteMessage(const Object& obj); | 544 void WriteMessage(const Object& obj); |
537 | 545 |
538 private: | 546 private: |
539 DISALLOW_COPY_AND_ASSIGN(MessageWriter); | 547 DISALLOW_COPY_AND_ASSIGN(MessageWriter); |
540 }; | 548 }; |
(...skipping 18 matching lines...) Expand all Loading... |
559 private: | 567 private: |
560 SnapshotWriter* writer_; | 568 SnapshotWriter* writer_; |
561 bool as_references_; | 569 bool as_references_; |
562 | 570 |
563 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 571 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
564 }; | 572 }; |
565 | 573 |
566 } // namespace dart | 574 } // namespace dart |
567 | 575 |
568 #endif // VM_SNAPSHOT_H_ | 576 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |