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 "platform/assert.h" | 6 #include "platform/assert.h" |
6 #include "vm/object_graph.h" | |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
11 class CounterVisitor : public ObjectGraph::Visitor { | 11 class CounterVisitor : public ObjectGraph::Visitor { |
12 public: | 12 public: |
13 // Records the number of objects and total size visited, excluding 'skip' | 13 // Records the number of objects and total size visited, excluding 'skip' |
14 // and any objects only reachable through 'skip'. | 14 // and any objects only reachable through 'skip'. |
15 CounterVisitor(RawObject* skip, RawObject* expected_parent) | 15 CounterVisitor(RawObject* skip, RawObject* expected_parent) |
16 : count_(0), size_(0), skip_(skip), expected_parent_(expected_parent) {} | 16 : count_(0), size_(0), skip_(skip), expected_parent_(expected_parent) {} |
(...skipping 13 matching lines...) Expand all Loading... |
30 int count() const { return count_; } | 30 int count() const { return count_; } |
31 int size() const { return size_; } | 31 int size() const { return size_; } |
32 | 32 |
33 private: | 33 private: |
34 int count_; | 34 int count_; |
35 intptr_t size_; | 35 intptr_t size_; |
36 RawObject* skip_; | 36 RawObject* skip_; |
37 RawObject* expected_parent_; | 37 RawObject* expected_parent_; |
38 }; | 38 }; |
39 | 39 |
40 | |
41 ISOLATE_UNIT_TEST_CASE(ObjectGraph) { | 40 ISOLATE_UNIT_TEST_CASE(ObjectGraph) { |
42 Isolate* isolate = thread->isolate(); | 41 Isolate* isolate = thread->isolate(); |
43 // Create a simple object graph with objects a, b, c, d: | 42 // Create a simple object graph with objects a, b, c, d: |
44 // a+->b+->c | 43 // a+->b+->c |
45 // + + | 44 // + + |
46 // | v | 45 // | v |
47 // +-->d | 46 // +-->d |
48 Array& a = Array::Handle(Array::New(12, Heap::kNew)); | 47 Array& a = Array::Handle(Array::New(12, Heap::kNew)); |
49 Array& b = Array::Handle(Array::New(2, Heap::kOld)); | 48 Array& b = Array::Handle(Array::New(2, Heap::kOld)); |
50 Array& c = Array::Handle(Array::New(0, Heap::kOld)); | 49 Array& c = Array::Handle(Array::New(0, Heap::kOld)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 Array& expected_a = Array::Handle(); | 132 Array& expected_a = Array::Handle(); |
134 expected_a ^= path.At(4); | 133 expected_a ^= path.At(4); |
135 EXPECT(expected_c.raw() == c.raw()); | 134 EXPECT(expected_c.raw() == c.raw()); |
136 EXPECT(expected_b.raw() == a.At(10)); | 135 EXPECT(expected_b.raw() == a.At(10)); |
137 EXPECT(expected_a.raw() == a.raw()); | 136 EXPECT(expected_a.raw() == a.raw()); |
138 } | 137 } |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 } // namespace dart | 141 } // namespace dart |
OLD | NEW |