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 // VMOptions=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'package:observatory/heap_snapshot.dart'; | 6 import 'package:observatory/heap_snapshot.dart'; |
7 import 'package:observatory/models.dart' as M; | 7 import 'package:observatory/models.dart' as M; |
8 import 'package:observatory/object_graph.dart'; | 8 import 'package:observatory/object_graph.dart'; |
9 import 'package:observatory/service_io.dart'; | 9 import 'package:observatory/service_io.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 import 'test_helper.dart'; | 11 import 'test_helper.dart'; |
12 | 12 |
13 class Foo { | 13 class Foo { |
14 Object left; | 14 Object left; |
15 Object right; | 15 Object right; |
16 } | 16 } |
17 | |
18 Foo r; | 17 Foo r; |
19 | 18 |
20 List lst; | 19 List lst; |
21 | 20 |
22 void script() { | 21 void script() { |
23 // Create 3 instances of Foo, with out-degrees | 22 // Create 3 instances of Foo, with out-degrees |
24 // 0 (for b), 1 (for a), and 2 (for staticFoo). | 23 // 0 (for b), 1 (for a), and 2 (for staticFoo). |
25 r = new Foo(); | 24 r = new Foo(); |
26 var a = new Foo(); | 25 var a = new Foo(); |
27 var b = new Foo(); | 26 var b = new Foo(); |
28 r.left = a; | 27 r.left = a; |
29 r.right = b; | 28 r.right = b; |
30 a.left = b; | 29 a.left = b; |
31 | 30 |
32 lst = new List(2); | 31 lst = new List(2); |
33 lst[0] = lst; // Self-loop. | 32 lst[0] = lst; // Self-loop. |
34 // Larger than any other fixed-size list in a fresh heap. | 33 // Larger than any other fixed-size list in a fresh heap. |
35 lst[1] = new List(123456); | 34 lst[1] = new List(123456); |
36 } | 35 } |
37 | 36 |
38 int fooId; | 37 int fooId; |
39 | 38 |
40 var tests = [ | 39 var tests = [ |
41 (Isolate isolate) async { | |
42 Library lib = await isolate.rootLibrary.load(); | |
43 expect(lib.classes.length, equals(1)); | |
44 Class fooClass = lib.classes.first; | |
45 fooId = fooClass.vmCid; | |
46 | 40 |
47 RawHeapSnapshot raw = | 41 (Isolate isolate) async { |
48 await isolate.fetchHeapSnapshot(M.HeapSnapshotRoots.vm, false).last; | 42 Library lib = await isolate.rootLibrary.load(); |
49 HeapSnapshot snapshot = new HeapSnapshot(); | 43 expect(lib.classes.length, equals(1)); |
50 await snapshot.loadProgress(isolate, raw).last; | 44 Class fooClass = lib.classes.first; |
51 ObjectGraph graph = snapshot.graph; | 45 fooId = fooClass.vmCid; |
52 | 46 |
53 expect(fooId, isNotNull); | 47 RawHeapSnapshot raw = |
54 Iterable<ObjectVertex> foos = | 48 await isolate.fetchHeapSnapshot(M.HeapSnapshotRoots.vm, false).last; |
55 graph.vertices.where((ObjectVertex obj) => obj.vmCid == fooId); | 49 HeapSnapshot snapshot = new HeapSnapshot(); |
56 expect(foos.length, equals(3)); | 50 await snapshot.loadProgress(isolate, raw).last; |
57 expect(foos.where((obj) => obj.successors.length == 0).length, equals(1)); | 51 ObjectGraph graph = snapshot.graph; |
58 expect(foos.where((obj) => obj.successors.length == 1).length, equals(1)); | |
59 expect(foos.where((obj) => obj.successors.length == 2).length, equals(1)); | |
60 | 52 |
61 ObjectVertex bVertex = | 53 expect(fooId, isNotNull); |
62 foos.where((ObjectVertex obj) => obj.successors.length == 0).first; | 54 Iterable<ObjectVertex> foos = graph.vertices.where( |
63 ObjectVertex aVertex = | 55 (ObjectVertex obj) => obj.vmCid == fooId); |
64 foos.where((ObjectVertex obj) => obj.successors.length == 1).first; | 56 expect(foos.length, equals(3)); |
65 ObjectVertex rVertex = | 57 expect(foos.where((obj) => obj.successors.length == 0).length, |
66 foos.where((ObjectVertex obj) => obj.successors.length == 2).first; | 58 equals(1)); |
| 59 expect(foos.where((obj) => obj.successors.length == 1).length, |
| 60 equals(1)); |
| 61 expect(foos.where((obj) => obj.successors.length == 2).length, |
| 62 equals(1)); |
67 | 63 |
68 // TODO(koda): Check actual byte sizes. | 64 ObjectVertex bVertex = foos.where( |
| 65 (ObjectVertex obj) => obj.successors.length == 0).first; |
| 66 ObjectVertex aVertex = foos.where( |
| 67 (ObjectVertex obj) => obj.successors.length == 1).first; |
| 68 ObjectVertex rVertex = foos.where( |
| 69 (ObjectVertex obj) => obj.successors.length == 2).first; |
69 | 70 |
70 expect(aVertex.retainedSize, equals(aVertex.shallowSize)); | 71 // TODO(koda): Check actual byte sizes. |
71 expect(bVertex.retainedSize, equals(bVertex.shallowSize)); | |
72 expect( | |
73 rVertex.retainedSize, | |
74 equals( | |
75 aVertex.shallowSize + bVertex.shallowSize + rVertex.shallowSize)); | |
76 | 72 |
77 Library corelib = | 73 expect(aVertex.retainedSize, equals(aVertex.shallowSize)); |
78 isolate.libraries.singleWhere((lib) => lib.uri == 'dart:core'); | 74 expect(bVertex.retainedSize, equals(bVertex.shallowSize)); |
79 await corelib.load(); | 75 expect(rVertex.retainedSize, equals(aVertex.shallowSize + |
80 Class _List = | 76 bVertex.shallowSize + |
81 corelib.classes.singleWhere((cls) => cls.vmName.startsWith('_List')); | 77 rVertex.shallowSize)); |
82 int kArrayCid = _List.vmCid; | 78 |
83 // startsWith to ignore the private mangling | 79 Library corelib = |
84 List<ObjectVertex> lists = new List.from( | 80 isolate.libraries.singleWhere((lib) => lib.uri == 'dart:core'); |
85 graph.vertices.where((ObjectVertex obj) => obj.vmCid == kArrayCid)); | 81 await corelib.load(); |
86 expect(lists.length >= 2, isTrue); | 82 Class _List = |
87 // Order by decreasing retained size. | 83 corelib.classes.singleWhere((cls) => cls.vmName.startsWith('_List')); |
88 lists.sort((u, v) => v.retainedSize - u.retainedSize); | 84 int kArrayCid = _List.vmCid; |
89 ObjectVertex first = lists[0]; | 85 // startsWith to ignore the private mangling |
90 ObjectVertex second = lists[1]; | 86 List<ObjectVertex> lists = new List.from(graph.vertices.where( |
91 // Check that the short list retains more than the long list inside. | 87 (ObjectVertex obj) => obj.vmCid == kArrayCid)); |
92 expect(first.successors.length, equals(2 + second.successors.length)); | 88 expect(lists.length >= 2, isTrue); |
93 // ... and specifically, that it retains exactly itself + the long one. | 89 // Order by decreasing retained size. |
94 expect(first.retainedSize, equals(first.shallowSize + second.shallowSize)); | 90 lists.sort((u, v) => v.retainedSize - u.retainedSize); |
95 }, | 91 ObjectVertex first = lists[0]; |
| 92 ObjectVertex second = lists[1]; |
| 93 // Check that the short list retains more than the long list inside. |
| 94 expect(first.successors.length, |
| 95 equals(2 + second.successors.length)); |
| 96 // ... and specifically, that it retains exactly itself + the long one. |
| 97 expect(first.retainedSize, |
| 98 equals(first.shallowSize + second.shallowSize)); |
| 99 }, |
| 100 |
96 ]; | 101 ]; |
97 | 102 |
98 main(args) => runIsolateTests(args, tests, testeeBefore: script); | 103 main(args) => runIsolateTests(args, tests, testeeBefore: script); |
OLD | NEW |