| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked | |
| 5 | |
| 6 library call_site_data_test; | |
| 7 | |
| 8 import 'package:observatory/service_io.dart'; | |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 import 'test_helper.dart'; | |
| 11 | |
| 12 class A { foo() => 'A'; } | |
| 13 class B { foo() => 'B'; } | |
| 14 class C { foo() => 'C'; } | |
| 15 class D { foo() => 'D'; } | |
| 16 class E { foo() => 'E'; } | |
| 17 class F { foo() => 'F'; } | |
| 18 class G { foo() => 'G'; } | |
| 19 class H { foo() => 'H'; } | |
| 20 | |
| 21 monomorphic(fooable) { | |
| 22 fooable.foo(); | |
| 23 return null; | |
| 24 } | |
| 25 polymorphic(fooable) { | |
| 26 fooable.foo(); | |
| 27 return null; | |
| 28 } | |
| 29 megamorphic(fooable) { | |
| 30 fooable.foo(); | |
| 31 return null; | |
| 32 } | |
| 33 | |
| 34 class Static { | |
| 35 static staticMethod() => 2; | |
| 36 } | |
| 37 staticCall() { | |
| 38 Static.staticMethod(); | |
| 39 return null; | |
| 40 } | |
| 41 constructorCall() { | |
| 42 new Static(); | |
| 43 return null; | |
| 44 } | |
| 45 topLevelMethod() => "TOP"; | |
| 46 topLevelCall() { | |
| 47 topLevelMethod(); | |
| 48 return null; | |
| 49 } | |
| 50 | |
| 51 class Super { bar() => "Super"; } | |
| 52 class Sub extends Super { bar() => super.bar(); } | |
| 53 | |
| 54 script() { | |
| 55 for (int i = 0; i < 10; i++) monomorphic(new A()); | |
| 56 | |
| 57 for (int i = 0; i < 10; i++) polymorphic(new A()); | |
| 58 for (int i = 0; i < 20; i++) polymorphic(new B()); | |
| 59 for (int i = 0; i < 30; i++) polymorphic(new C()); | |
| 60 | |
| 61 for (int i = 0; i < 10; i++) megamorphic(new A()); | |
| 62 for (int i = 0; i < 20; i++) megamorphic(new B()); | |
| 63 for (int i = 0; i < 30; i++) megamorphic(new C()); | |
| 64 for (int i = 0; i < 40; i++) megamorphic(new D()); | |
| 65 for (int i = 0; i < 50; i++) megamorphic(new E()); | |
| 66 for (int i = 0; i < 60; i++) megamorphic(new F()); | |
| 67 for (int i = 0; i < 70; i++) megamorphic(new G()); | |
| 68 for (int i = 0; i < 80; i++) megamorphic(new H()); | |
| 69 | |
| 70 for (int i = 0; i < 10; i++) staticCall(); | |
| 71 | |
| 72 for (int i = 0; i < 10; i++) constructorCall(); | |
| 73 | |
| 74 for (int i = 0; i < 10; i++) topLevelCall(); | |
| 75 | |
| 76 for (int i = 0; i < 15; i++) new Sub().bar(); | |
| 77 } | |
| 78 | |
| 79 | |
| 80 Set<String> stringifyCacheEntries(Map callSite) { | |
| 81 return callSite['cacheEntries'].map((entry) { | |
| 82 return "${entry['receiverContainer']['name']}:${entry['count']}"; | |
| 83 }).toSet(); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 testMonomorphic(Isolate isolate) async { | |
| 88 Library lib = await isolate.rootLib.load(); | |
| 89 ServiceFunction func = | |
| 90 lib.functions.singleWhere((f) => f.name == 'monomorphic'); | |
| 91 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 92 { 'targetId': func.id }); | |
| 93 expect(response['type'], equals('CodeCoverage')); | |
| 94 Map callSite = response['coverage'].single['callSites'].single; | |
| 95 expect(callSite['name'], equals('foo')); | |
| 96 expect(stringifyCacheEntries(callSite), | |
| 97 equals(['A:10'].toSet())); | |
| 98 } | |
| 99 | |
| 100 testPolymorphic(Isolate isolate) async { | |
| 101 Library lib = await isolate.rootLib.load(); | |
| 102 ServiceFunction func = | |
| 103 lib.functions.singleWhere((f) => f.name == 'polymorphic'); | |
| 104 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 105 { 'targetId': func.id }); | |
| 106 expect(response['type'], equals('CodeCoverage')); | |
| 107 Map callSite = response['coverage'].single['callSites'].single; | |
| 108 expect(callSite['name'], equals('foo')); | |
| 109 expect(stringifyCacheEntries(callSite), | |
| 110 equals(['A:10', 'B:20', 'C:30'].toSet())); | |
| 111 } | |
| 112 | |
| 113 testMegamorphic(Isolate isolate) async { | |
| 114 Library lib = await isolate.rootLib.load(); | |
| 115 ServiceFunction func = | |
| 116 lib.functions.singleWhere((f) => f.name == 'megamorphic'); | |
| 117 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 118 { 'targetId': func.id }); | |
| 119 expect(response['type'], equals('CodeCoverage')); | |
| 120 Map callSite = response['coverage'].single['callSites'].single; | |
| 121 expect(callSite['name'], equals('foo')); | |
| 122 expect(stringifyCacheEntries(callSite), | |
| 123 equals(['A:10', 'B:20', 'C:30', 'D:40', | |
| 124 'E:50', 'F:60', 'G:70', 'H:80'].toSet())); | |
| 125 } | |
| 126 | |
| 127 testStaticCall(Isolate isolate) async { | |
| 128 Library lib = await isolate.rootLib.load(); | |
| 129 ServiceFunction func = | |
| 130 lib.functions.singleWhere((f) => f.name == 'staticCall'); | |
| 131 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 132 { 'targetId': func.id }); | |
| 133 expect(response['type'], equals('CodeCoverage')); | |
| 134 Map callSite = response['coverage'].single['callSites'].single; | |
| 135 expect(callSite['name'], equals('staticMethod')); | |
| 136 expect(stringifyCacheEntries(callSite), | |
| 137 equals(['Static:10'].toSet())); | |
| 138 } | |
| 139 | |
| 140 testConstructorCall(Isolate isolate) async { | |
| 141 Library lib = await isolate.rootLib.load(); | |
| 142 ServiceFunction func = | |
| 143 lib.functions.singleWhere((f) => f.name == 'constructorCall'); | |
| 144 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 145 { 'targetId': func.id }); | |
| 146 expect(response['type'], equals('CodeCoverage')); | |
| 147 Map callSite = response['coverage'].single['callSites'].single; | |
| 148 expect(callSite['name'], equals('Static.')); | |
| 149 expect(stringifyCacheEntries(callSite), | |
| 150 equals(['Static:10'].toSet())); | |
| 151 } | |
| 152 | |
| 153 testTopLevelCall(Isolate isolate) async { | |
| 154 Library lib = await isolate.rootLib.load(); | |
| 155 ServiceFunction func = | |
| 156 lib.functions.singleWhere((f) => f.name == 'topLevelCall'); | |
| 157 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 158 { 'targetId': func.id }); | |
| 159 expect(response['type'], equals('CodeCoverage')); | |
| 160 Map callSite = response['coverage'].single['callSites'].single; | |
| 161 expect(callSite['name'], equals('topLevelMethod')); | |
| 162 expect(stringifyCacheEntries(callSite), | |
| 163 equals(['call_site_data_test:10'].toSet())); | |
| 164 } | |
| 165 | |
| 166 testSuperCall(Isolate isolate) async { | |
| 167 Library lib = await isolate.rootLib.load(); | |
| 168 Class cls = await lib.classes.singleWhere((f) => f.name == 'Sub').load(); | |
| 169 ServiceFunction func = cls.functions.singleWhere((f) => f.name == 'bar'); | |
| 170 Map response = await isolate.invokeRpcNoUpgrade('_getCallSiteData', | |
| 171 { 'targetId': func.id }); | |
| 172 expect(response['type'], equals('CodeCoverage')); | |
| 173 Map callSite = response['coverage'].single['callSites'].single; | |
| 174 expect(callSite['name'], equals('bar')); | |
| 175 expect(stringifyCacheEntries(callSite), | |
| 176 equals(['Super:15'].toSet())); | |
| 177 } | |
| 178 | |
| 179 var tests = [ | |
| 180 testMonomorphic, | |
| 181 testPolymorphic, | |
| 182 testMegamorphic, | |
| 183 testStaticCall, | |
| 184 testConstructorCall, | |
| 185 testTopLevelCall, | |
| 186 testSuperCall ]; | |
| 187 | |
| 188 main(args) => runIsolateTests(args, tests, testeeBefore: script); | |
| OLD | NEW |