| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 #include "vm/object_graph.h" | 5 #include "vm/object_graph.h" |
| 6 | 6 |
| 7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
| 8 #include "vm/dart_api_state.h" |
| 8 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
| 9 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| 10 #include "vm/object.h" | 11 #include "vm/object.h" |
| 11 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
| 12 #include "vm/raw_object.h" | 13 #include "vm/raw_object.h" |
| 13 #include "vm/reusable_handles.h" | 14 #include "vm/reusable_handles.h" |
| 14 #include "vm/visitor.h" | 15 #include "vm/visitor.h" |
| 15 | 16 |
| 16 namespace dart { | 17 namespace dart { |
| 17 | 18 |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 590 |
| 590 intptr_t count() const { return count_; } | 591 intptr_t count() const { return count_; } |
| 591 | 592 |
| 592 private: | 593 private: |
| 593 WriteStream* stream_; | 594 WriteStream* stream_; |
| 594 WritePointerVisitor ptr_writer_; | 595 WritePointerVisitor ptr_writer_; |
| 595 ObjectGraph::SnapshotRoots roots_; | 596 ObjectGraph::SnapshotRoots roots_; |
| 596 intptr_t count_; | 597 intptr_t count_; |
| 597 }; | 598 }; |
| 598 | 599 |
| 600 class WriteGraphExternalSizesVisitor : public HandleVisitor { |
| 601 public: |
| 602 WriteGraphExternalSizesVisitor(Thread* thread, WriteStream* stream) |
| 603 : HandleVisitor(thread), stream_(stream) {} |
| 604 |
| 605 void VisitHandle(uword addr) { |
| 606 FinalizablePersistentHandle* weak_persistent_handle = |
| 607 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
| 608 if (!weak_persistent_handle->raw()->IsHeapObject()) { |
| 609 return; // Free handle. |
| 610 } |
| 611 |
| 612 WritePtr(weak_persistent_handle->raw(), stream_); |
| 613 stream_->WriteUnsigned(weak_persistent_handle->external_size()); |
| 614 } |
| 615 |
| 616 private: |
| 617 WriteStream* stream_; |
| 618 }; |
| 619 |
| 599 intptr_t ObjectGraph::Serialize(WriteStream* stream, | 620 intptr_t ObjectGraph::Serialize(WriteStream* stream, |
| 600 SnapshotRoots roots, | 621 SnapshotRoots roots, |
| 601 bool collect_garbage) { | 622 bool collect_garbage) { |
| 602 if (collect_garbage) { | 623 if (collect_garbage) { |
| 603 isolate()->heap()->CollectAllGarbage(); | 624 isolate()->heap()->CollectAllGarbage(); |
| 604 } | 625 } |
| 605 // Current encoding assumes objects do not move, so promote everything to old. | 626 // Current encoding assumes objects do not move, so promote everything to old. |
| 606 isolate()->heap()->new_space()->Evacuate(); | 627 isolate()->heap()->new_space()->Evacuate(); |
| 607 HeapIterationScope iteration_scope(Thread::Current(), true); | 628 HeapIterationScope iteration_scope(Thread::Current(), true); |
| 608 | 629 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 634 // Write stack "object". | 655 // Write stack "object". |
| 635 WriteHeader(kStackAddress, 0, kStackCid, stream); | 656 WriteHeader(kStackAddress, 0, kStackCid, stream); |
| 636 WritePointerVisitor ptr_writer(isolate(), stream, true); | 657 WritePointerVisitor ptr_writer(isolate(), stream, true); |
| 637 isolate()->VisitStackPointers(&ptr_writer, false); | 658 isolate()->VisitStackPointers(&ptr_writer, false); |
| 638 stream->WriteUnsigned(0); | 659 stream->WriteUnsigned(0); |
| 639 } | 660 } |
| 640 } | 661 } |
| 641 | 662 |
| 642 WriteGraphVisitor visitor(isolate(), stream, roots); | 663 WriteGraphVisitor visitor(isolate(), stream, roots); |
| 643 IterateObjects(&visitor); | 664 IterateObjects(&visitor); |
| 665 stream->WriteUnsigned(0); |
| 666 |
| 667 WriteGraphExternalSizesVisitor external_visitor(Thread::Current(), stream); |
| 668 isolate()->VisitWeakPersistentHandles(&external_visitor); |
| 669 stream->WriteUnsigned(0); |
| 644 | 670 |
| 645 intptr_t object_count = visitor.count(); | 671 intptr_t object_count = visitor.count(); |
| 646 if (roots == kVM) { | 672 if (roots == kVM) { |
| 647 object_count += 1; // root | 673 object_count += 1; // root |
| 648 } else { | 674 } else { |
| 649 object_count += 2; // root and stack | 675 object_count += 2; // root and stack |
| 650 } | 676 } |
| 651 return object_count; | 677 return object_count; |
| 652 } | 678 } |
| 653 | 679 |
| 654 } // namespace dart | 680 } // namespace dart |
| OLD | NEW |