Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Side by Side Diff: runtime/vm/snapshot.h

Issue 383063005: Refactor snapshot writer's forward list into a reusable class. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 data[Snapshot::kSnapshotFlagIndex] = kind; 480 data[Snapshot::kSnapshotFlagIndex] = kind;
481 } 481 }
482 482
483 private: 483 private:
484 WriteStream stream_; 484 WriteStream stream_;
485 485
486 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter); 486 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseWriter);
487 }; 487 };
488 488
489 489
490 class ForwardList {
491 public:
492 explicit ForwardList(intptr_t first_object_id)
493 : first_object_id_(first_object_id),
siva 2014/07/11 19:57:48 normally we initialize all the fields in the list,
koda 2014/07/11 21:06:39 Done.
494 first_unprocessed_object_id_(first_object_id) {}
495
496 class Node : public ZoneAllocated {
497 public:
498 Node(RawObject* raw, uword tags, SerializeState state)
499 : raw_(raw), tags_(tags), state_(state) {}
500 RawObject* raw() const { return raw_; }
501 uword tags() const { return tags_; }
502 bool is_serialized() const { return state_ == kIsSerialized; }
503
504 private:
505 // Private to ensure the invariant of first_unprocessed_object_id_.
506 void set_state(SerializeState value) { state_ = value; }
507
508 RawObject* raw_;
509 uword tags_;
510 SerializeState state_;
511
512 friend class ForwardList;
513 DISALLOW_COPY_AND_ASSIGN(Node);
514 };
515
516 Node* NodeForObjectId(intptr_t object_id) const {
517 return nodes_[object_id - first_object_id_];
518 }
519
520 // Returns the id for the added object.
521 intptr_t MarkAndAddObject(RawObject* raw, SerializeState state);
522
523 // Exhaustively processes all unserialized objects in this list. 'writer' may
524 // concurrently add more objects.
525 void SerializeAll(ObjectVisitor* writer);
526
527 // Restores the tags of all objects in this list.
528 void UnmarkAll() const;
529
530 private:
531 intptr_t first_object_id() const { return first_object_id_; }
532 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; }
533
534 const intptr_t first_object_id_;
535 GrowableArray<Node*> nodes_;
536 intptr_t first_unprocessed_object_id_;
siva 2014/07/11 19:57:49 DISALLOW_COPY_AND_ASSSIGN(ForwardList);
koda 2014/07/11 21:06:39 Done.
537 };
538
539
490 class SnapshotWriter : public BaseWriter { 540 class SnapshotWriter : public BaseWriter {
491 protected: 541 protected:
492 SnapshotWriter(Snapshot::Kind kind, 542 SnapshotWriter(Snapshot::Kind kind,
493 uint8_t** buffer, 543 uint8_t** buffer,
494 ReAlloc alloc, 544 ReAlloc alloc,
495 intptr_t initial_size); 545 intptr_t initial_size);
496 546
497 public: 547 public:
498 // Snapshot kind. 548 // Snapshot kind.
499 Snapshot::Kind kind() const { return kind_; } 549 Snapshot::Kind kind() const { return kind_; }
500 550
501 // Serialize an object into the buffer. 551 // Serialize an object into the buffer.
502 void WriteObject(RawObject* raw); 552 void WriteObject(RawObject* raw);
503 553
504 uword GetObjectTags(RawObject* raw); 554 uword GetObjectTags(RawObject* raw);
505 555
506 Exceptions::ExceptionType exception_type() const { 556 Exceptions::ExceptionType exception_type() const {
507 return exception_type_; 557 return exception_type_;
508 } 558 }
509 void set_exception_type(Exceptions::ExceptionType type) { 559 void set_exception_type(Exceptions::ExceptionType type) {
510 exception_type_ = type; 560 exception_type_ = type;
511 } 561 }
512 const char* exception_msg() const { return exception_msg_; } 562 const char* exception_msg() const { return exception_msg_; }
513 void set_exception_msg(const char* msg) { 563 void set_exception_msg(const char* msg) {
514 exception_msg_ = msg; 564 exception_msg_ = msg;
515 } 565 }
516 void ThrowException(Exceptions::ExceptionType type, const char* msg); 566 void ThrowException(Exceptions::ExceptionType type, const char* msg);
517 567
518 protected: 568 protected:
519 class ForwardObjectNode : public ZoneAllocated { 569 void UnmarkAll() {
520 public: 570 forward_list_.UnmarkAll();
521 ForwardObjectNode(RawObject* raw, uword tags, SerializeState state) 571 }
522 : raw_(raw), tags_(tags), state_(state) {}
523 RawObject* raw() const { return raw_; }
524 uword tags() const { return tags_; }
525 bool is_serialized() const { return state_ == kIsSerialized; }
526 void set_state(SerializeState value) { state_ = value; }
527
528 private:
529 RawObject* raw_;
530 uword tags_;
531 SerializeState state_;
532
533 DISALLOW_COPY_AND_ASSIGN(ForwardObjectNode);
534 };
535
536 intptr_t MarkObject(RawObject* raw, SerializeState state);
537 void UnmarkAll();
538 572
539 bool CheckAndWritePredefinedObject(RawObject* raw); 573 bool CheckAndWritePredefinedObject(RawObject* raw);
540 void HandleVMIsolateObject(RawObject* raw); 574 void HandleVMIsolateObject(RawObject* raw);
541 575
542 void WriteObjectRef(RawObject* raw); 576 void WriteObjectRef(RawObject* raw);
543 void WriteClassId(RawClass* cls); 577 void WriteClassId(RawClass* cls);
544 void WriteObjectImpl(RawObject* raw); 578 void WriteObjectImpl(RawObject* raw);
545 void WriteInlinedObject(RawObject* raw); 579 void WriteInlinedObject(RawObject* raw);
546 void WriteForwardedObjects(); 580 void WriteForwardedObjects();
547 void ArrayWriteTo(intptr_t object_id, 581 void ArrayWriteTo(intptr_t object_id,
548 intptr_t array_kind, 582 intptr_t array_kind,
549 intptr_t tags, 583 intptr_t tags,
550 RawSmi* length, 584 RawSmi* length,
551 RawTypeArguments* type_arguments, 585 RawTypeArguments* type_arguments,
552 RawObject* data[]); 586 RawObject* data[]);
553 void CheckIfSerializable(RawClass* cls); 587 void CheckIfSerializable(RawClass* cls);
554 void SetWriteException(Exceptions::ExceptionType type, const char* msg); 588 void SetWriteException(Exceptions::ExceptionType type, const char* msg);
555 void WriteInstance(intptr_t object_id, 589 void WriteInstance(intptr_t object_id,
556 RawObject* raw, 590 RawObject* raw,
557 RawClass* cls, 591 RawClass* cls,
558 intptr_t tags); 592 intptr_t tags);
559 void WriteInstanceRef(RawObject* raw, RawClass* cls); 593 void WriteInstanceRef(RawObject* raw, RawClass* cls);
560 594
561 ObjectStore* object_store() const { return object_store_; } 595 ObjectStore* object_store() const { return object_store_; }
562 596
563 private: 597 private:
564 Snapshot::Kind kind_; 598 Snapshot::Kind kind_;
565 ObjectStore* object_store_; // Object store for common classes. 599 ObjectStore* object_store_; // Object store for common classes.
566 ClassTable* class_table_; // Class table for the class index to class lookup. 600 ClassTable* class_table_; // Class table for the class index to class lookup.
567 GrowableArray<ForwardObjectNode*> forward_list_; 601 ForwardList forward_list_;
568 Exceptions::ExceptionType exception_type_; // Exception type. 602 Exceptions::ExceptionType exception_type_; // Exception type.
569 const char* exception_msg_; // Message associated with exception. 603 const char* exception_msg_; // Message associated with exception.
570 604
571 friend class RawArray; 605 friend class RawArray;
572 friend class RawClass; 606 friend class RawClass;
573 friend class RawClosureData; 607 friend class RawClosureData;
574 friend class RawGrowableObjectArray; 608 friend class RawGrowableObjectArray;
575 friend class RawImmutableArray; 609 friend class RawImmutableArray;
576 friend class RawJSRegExp; 610 friend class RawJSRegExp;
577 friend class RawLibrary; 611 friend class RawLibrary;
578 friend class RawLiteralToken; 612 friend class RawLiteralToken;
613 friend class RawMirrorReference;
579 friend class RawReceivePort; 614 friend class RawReceivePort;
580 friend class RawScript; 615 friend class RawScript;
581 friend class RawStacktrace; 616 friend class RawStacktrace;
582 friend class RawTokenStream; 617 friend class RawTokenStream;
583 friend class RawTypeArguments; 618 friend class RawTypeArguments;
584 friend class RawMirrorReference; 619 friend class RawUserTag;
585 friend class SnapshotWriterVisitor; 620 friend class SnapshotWriterVisitor;
586 friend class RawUserTag; 621 friend class WriteInlinedObjectVisitor;
587 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); 622 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter);
588 }; 623 };
589 624
590 625
591 class FullSnapshotWriter : public SnapshotWriter { 626 class FullSnapshotWriter : public SnapshotWriter {
592 public: 627 public:
593 static const intptr_t kInitialSize = 64 * KB; 628 static const intptr_t kInitialSize = 64 * KB;
594 FullSnapshotWriter(uint8_t** buffer, ReAlloc alloc) 629 FullSnapshotWriter(uint8_t** buffer, ReAlloc alloc)
595 : SnapshotWriter(Snapshot::kFull, buffer, alloc, kInitialSize) { 630 : SnapshotWriter(Snapshot::kFull, buffer, alloc, kInitialSize) {
596 ASSERT(buffer != NULL); 631 ASSERT(buffer != NULL);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 private: 695 private:
661 SnapshotWriter* writer_; 696 SnapshotWriter* writer_;
662 bool as_references_; 697 bool as_references_;
663 698
664 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); 699 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor);
665 }; 700 };
666 701
667 } // namespace dart 702 } // namespace dart
668 703
669 #endif // VM_SNAPSHOT_H_ 704 #endif // VM_SNAPSHOT_H_
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698