Chromium Code Reviews| 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 part of service; | 5 part of service; |
| 6 | 6 |
| 7 /// A [ServiceObject] is an object known to the VM service and is tied | 7 /// A [ServiceObject] is an object known to the VM service and is tied |
| 8 /// to an owning [Isolate]. | 8 /// to an owning [Isolate]. |
| 9 abstract class ServiceObject extends Observable { | 9 abstract class ServiceObject extends Observable { |
| 10 static int LexicalSortName(ServiceObject o1, ServiceObject o2) { | 10 static int LexicalSortName(ServiceObject o1, ServiceObject o2) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 switch (type) { | 72 switch (type) { |
| 73 case 'Class': | 73 case 'Class': |
| 74 obj = new Class._empty(owner); | 74 obj = new Class._empty(owner); |
| 75 break; | 75 break; |
| 76 case 'Code': | 76 case 'Code': |
| 77 obj = new Code._empty(owner); | 77 obj = new Code._empty(owner); |
| 78 break; | 78 break; |
| 79 case 'Error': | 79 case 'Error': |
| 80 obj = new DartError._empty(owner); | 80 obj = new DartError._empty(owner); |
| 81 break; | 81 break; |
| 82 case 'Function': | |
| 83 obj = new Function._empty(owner); | |
| 84 break; | |
| 82 case 'Isolate': | 85 case 'Isolate': |
| 83 obj = new Isolate._empty(owner.vm); | 86 obj = new Isolate._empty(owner.vm); |
| 84 break; | 87 break; |
| 85 case 'Library': | 88 case 'Library': |
| 86 obj = new Library._empty(owner); | 89 obj = new Library._empty(owner); |
| 87 break; | 90 break; |
| 91 case 'Null': | |
| 92 return null; | |
| 88 case 'ServiceError': | 93 case 'ServiceError': |
| 89 obj = new ServiceError._empty(owner); | 94 obj = new ServiceError._empty(owner); |
| 90 break; | 95 break; |
| 91 case 'ServiceEvent': | 96 case 'ServiceEvent': |
| 92 obj = new ServiceEvent._empty(owner); | 97 obj = new ServiceEvent._empty(owner); |
| 93 break; | 98 break; |
| 94 case 'ServiceException': | 99 case 'ServiceException': |
| 95 obj = new ServiceException._empty(owner); | 100 obj = new ServiceException._empty(owner); |
| 96 break; | 101 break; |
| 97 case 'Script': | 102 case 'Script': |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 if (map == null) { | 686 if (map == null) { |
| 682 return null; | 687 return null; |
| 683 } | 688 } |
| 684 String id = map['id']; | 689 String id = map['id']; |
| 685 var obj = _cache[id]; | 690 var obj = _cache[id]; |
| 686 if (obj != null) { | 691 if (obj != null) { |
| 687 return obj; | 692 return obj; |
| 688 } | 693 } |
| 689 // Build the object from the map directly. | 694 // Build the object from the map directly. |
| 690 obj = new ServiceObject._fromMap(this, map); | 695 obj = new ServiceObject._fromMap(this, map); |
| 691 if (obj.canCache) { | 696 if (obj != null && obj.canCache) { |
| 692 _cache[id] = obj; | 697 _cache[id] = obj; |
| 693 } | 698 } |
| 694 return obj; | 699 return obj; |
| 695 } | 700 } |
| 696 | 701 |
| 697 Future<ServiceObject> get(String id) { | 702 Future<ServiceObject> get(String id) { |
| 698 // Do not allow null ids or empty ids. | 703 // Do not allow null ids or empty ids. |
| 699 assert(id != null && id != ''); | 704 assert(id != null && id != ''); |
| 700 var obj = _cache[id]; | 705 var obj = _cache[id]; |
| 701 if (obj != null) { | 706 if (obj != null) { |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1029 } | 1034 } |
| 1030 } | 1035 } |
| 1031 } | 1036 } |
| 1032 | 1037 |
| 1033 class Library extends ServiceObject with Coverage { | 1038 class Library extends ServiceObject with Coverage { |
| 1034 @observable String url; | 1039 @observable String url; |
| 1035 @reflectable final imports = new ObservableList<Library>(); | 1040 @reflectable final imports = new ObservableList<Library>(); |
| 1036 @reflectable final scripts = new ObservableList<Script>(); | 1041 @reflectable final scripts = new ObservableList<Script>(); |
| 1037 @reflectable final classes = new ObservableList<Class>(); | 1042 @reflectable final classes = new ObservableList<Class>(); |
| 1038 @reflectable final variables = new ObservableList<ServiceMap>(); | 1043 @reflectable final variables = new ObservableList<ServiceMap>(); |
| 1039 @reflectable final functions = new ObservableList<ServiceMap>(); | 1044 @reflectable final functions = new ObservableList<Function>(); |
| 1040 | 1045 |
| 1041 bool get canCache => true; | 1046 bool get canCache => true; |
| 1042 bool get immutable => false; | 1047 bool get immutable => false; |
| 1043 | 1048 |
| 1044 Library._empty(ServiceObjectOwner owner) : super._empty(owner); | 1049 Library._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 1045 | 1050 |
| 1046 void _update(ObservableMap map, bool mapIsRef) { | 1051 void _update(ObservableMap map, bool mapIsRef) { |
| 1047 url = map['url']; | 1052 url = map['url']; |
| 1048 var shortUrl = url; | 1053 var shortUrl = url; |
| 1049 if (url.startsWith('file://') || | 1054 if (url.startsWith('file://') || |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 @observable ServiceMap error; | 1134 @observable ServiceMap error; |
| 1130 | 1135 |
| 1131 final Allocations newSpace = new Allocations(); | 1136 final Allocations newSpace = new Allocations(); |
| 1132 final Allocations oldSpace = new Allocations(); | 1137 final Allocations oldSpace = new Allocations(); |
| 1133 | 1138 |
| 1134 bool get hasNoAllocations => newSpace.empty && oldSpace.empty; | 1139 bool get hasNoAllocations => newSpace.empty && oldSpace.empty; |
| 1135 | 1140 |
| 1136 @reflectable final children = new ObservableList<Class>(); | 1141 @reflectable final children = new ObservableList<Class>(); |
| 1137 @reflectable final subClasses = new ObservableList<Class>(); | 1142 @reflectable final subClasses = new ObservableList<Class>(); |
| 1138 @reflectable final fields = new ObservableList<ServiceMap>(); | 1143 @reflectable final fields = new ObservableList<ServiceMap>(); |
| 1139 @reflectable final functions = new ObservableList<ServiceMap>(); | 1144 @reflectable final functions = new ObservableList<Function>(); |
| 1140 @reflectable final interfaces = new ObservableList<Class>(); | 1145 @reflectable final interfaces = new ObservableList<Class>(); |
| 1141 | 1146 |
| 1142 bool get canCache => true; | 1147 bool get canCache => true; |
| 1143 bool get immutable => false; | 1148 bool get immutable => false; |
| 1144 | 1149 |
| 1145 Class._empty(ServiceObjectOwner owner) : super._empty(owner); | 1150 Class._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 1146 | 1151 |
| 1147 String toString() { | 1152 String toString() { |
| 1148 return 'Service Class: $vmName'; | 1153 return 'Service Class: $vmName'; |
| 1149 } | 1154 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 return; | 1215 return; |
| 1211 } | 1216 } |
| 1212 children.add(cls); | 1217 children.add(cls); |
| 1213 } | 1218 } |
| 1214 | 1219 |
| 1215 Future<ServiceObject> get(String command) { | 1220 Future<ServiceObject> get(String command) { |
| 1216 return isolate.get(id + "/$command"); | 1221 return isolate.get(id + "/$command"); |
| 1217 } | 1222 } |
| 1218 } | 1223 } |
| 1219 | 1224 |
| 1225 class FunctionKind { | |
| 1226 final String _strValue; | |
| 1227 FunctionKind._internal(this._strValue); | |
| 1228 toString() => _strValue; | |
| 1229 bool isFake() => [kCollected, kNative, kTag, kReused].contains(this); | |
| 1230 | |
| 1231 static FunctionKind fromJSON(String value) { | |
| 1232 switch(value) { | |
| 1233 case 'kRegularFunction': return kRegularFunction; | |
| 1234 case 'kClosureFunction': return kClosureFunction; | |
| 1235 case 'kGetterFunction': return kGetterFunction; | |
| 1236 case 'kSetterFunction': return kSetterFunction; | |
| 1237 case 'kConstructor': return kConstructor; | |
| 1238 case 'kImplicitGetterFunction': return kImplicitGetterFunction; | |
| 1239 case 'kImplicitSetterFunction': return kImplicitSetterFunction; | |
| 1240 case 'kStaticInitializer': return kStaticInitializer; | |
| 1241 case 'kMethodExtractor': return kMethodExtractor; | |
| 1242 case 'kNoSuchMethodDispatcher': return kNoSuchMethodDispatcher; | |
| 1243 case 'kInvokeFieldDispatcher': return kInvokeFieldDispatcher; | |
| 1244 case 'Collected': return kCollected; | |
| 1245 case 'Native': return kNative; | |
| 1246 case 'Tag': return kTag; | |
| 1247 case 'Reused': return kReused; | |
| 1248 } | |
| 1249 return kUNKNOWN; | |
| 1250 } | |
| 1251 | |
| 1252 static FunctionKind kRegularFunction = new FunctionKind._internal('function'); | |
| 1253 static FunctionKind kClosureFunction = new FunctionKind._internal('closure fun ction'); | |
| 1254 static FunctionKind kGetterFunction = new FunctionKind._internal('getter funct ion'); | |
| 1255 static FunctionKind kSetterFunction = new FunctionKind._internal('setter funct ion'); | |
| 1256 static FunctionKind kConstructor = new FunctionKind._internal('constructor'); | |
| 1257 static FunctionKind kImplicitGetterFunction = new FunctionKind._internal('impl icit getter function'); | |
| 1258 static FunctionKind kImplicitSetterFunction = new FunctionKind._internal('impl icit setter function'); | |
| 1259 static FunctionKind kStaticInitializer = new FunctionKind._internal('static in itializer'); | |
| 1260 static FunctionKind kMethodExtractor = new FunctionKind._internal('method extr actor'); | |
| 1261 static FunctionKind kNoSuchMethodDispatcher = new FunctionKind._internal('noSu chMethod dispatcher'); | |
| 1262 static FunctionKind kInvokeFieldDispatcher = new FunctionKind._internal('invok e field dispatcher'); | |
| 1263 static FunctionKind kCollected = new FunctionKind._internal('Collected'); | |
| 1264 static FunctionKind kNative = new FunctionKind._internal('Native'); | |
| 1265 static FunctionKind kTag = new FunctionKind._internal('Tag'); | |
| 1266 static FunctionKind kReused = new FunctionKind._internal('Reused'); | |
| 1267 static FunctionKind kUNKNOWN = new FunctionKind._internal('UNKNOWN'); | |
| 1268 } | |
| 1269 | |
| 1270 class Function extends ServiceObject { | |
|
Michael Lippautz (Google)
2014/07/09 20:22:24
Function clashes with dart.core's Function in the
Cutch
2014/07/09 20:43:31
Yes, ServiceFunction, DartFunction, ?
Michael Lippautz (Google)
2014/07/09 21:02:11
ServiceFunction, done.
| |
| 1271 @observable Class owningClass; | |
| 1272 @observable Library owningLibrary; | |
| 1273 @observable bool isStatic; | |
| 1274 @observable bool isConst; | |
| 1275 @observable Function parent; | |
| 1276 @observable Script script; | |
| 1277 @observable int tokenPos; | |
| 1278 @observable int endTokenPos; | |
| 1279 @observable Code code; | |
| 1280 @observable Code unoptimizedCode; | |
| 1281 @observable bool isOptimizable; | |
| 1282 @observable bool isInlinable; | |
| 1283 @observable FunctionKind kind; | |
| 1284 @observable int deoptimizations; | |
| 1285 @observable String qualifiedName; | |
| 1286 @observable int usageCounter; | |
| 1287 @observable bool isDart; | |
| 1288 | |
| 1289 Function._empty(ServiceObject owner) : super._empty(owner); | |
| 1290 | |
| 1291 void _update(ObservableMap map, bool mapIsRef) { | |
| 1292 name = map['user_name']; | |
| 1293 vmName = map['name']; | |
| 1294 | |
| 1295 _upgradeCollection(map, isolate); | |
| 1296 | |
| 1297 owningClass = map.containsKey('owningClass') ? map['owningClass'] : null; | |
| 1298 owningLibrary = map.containsKey('owningLibrary') ? map['owningLibrary'] : nu ll; | |
| 1299 kind = FunctionKind.fromJSON(map['kind']); | |
| 1300 isDart = !kind.isFake(); | |
| 1301 | |
| 1302 if (mapIsRef) { return; } | |
| 1303 | |
| 1304 isStatic = map['isStatic']; | |
| 1305 isConst = map['isConst']; | |
| 1306 parent = map['parent']; | |
| 1307 script = map['script']; | |
| 1308 tokenPos = map['tokenPos']; | |
| 1309 endTokenPos = map['endTokenPos']; | |
| 1310 code = map['code']; | |
| 1311 unoptimizedCode = map['unoptimized_code']; | |
| 1312 isOptimizable = map['is_optimizable']; | |
| 1313 isInlinable = map['is_inlinable']; | |
| 1314 deoptimizations = map['deoptimizations']; | |
| 1315 usageCounter = map['usage_counter']; | |
| 1316 | |
| 1317 if (parent == null) { | |
| 1318 qualifiedName = (owningClass != null) ? | |
| 1319 "${owningClass.name}.${name}" : | |
| 1320 name; | |
| 1321 } else { | |
| 1322 qualifiedName = "${parent.qualifiedName}.${name}"; | |
| 1323 } | |
| 1324 | |
| 1325 } | |
| 1326 } | |
| 1327 | |
| 1220 class ScriptLine extends Observable { | 1328 class ScriptLine extends Observable { |
| 1221 final int line; | 1329 final int line; |
| 1222 final String text; | 1330 final String text; |
| 1223 @observable int hits; | 1331 @observable int hits; |
| 1224 ScriptLine(this.line, this.text); | 1332 ScriptLine(this.line, this.text); |
| 1225 } | 1333 } |
| 1226 | 1334 |
| 1227 class Script extends ServiceObject with Coverage { | 1335 class Script extends ServiceObject with Coverage { |
| 1228 final lines = new ObservableList<ScriptLine>(); | 1336 final lines = new ObservableList<ScriptLine>(); |
| 1229 final _hits = new Map<int, int>(); | 1337 final _hits = new Map<int, int>(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 @reflectable int inclusiveTicks = 0; | 1641 @reflectable int inclusiveTicks = 0; |
| 1534 @reflectable int startAddress = 0; | 1642 @reflectable int startAddress = 0; |
| 1535 @reflectable int endAddress = 0; | 1643 @reflectable int endAddress = 0; |
| 1536 @reflectable final callers = new List<CodeCallCount>(); | 1644 @reflectable final callers = new List<CodeCallCount>(); |
| 1537 @reflectable final callees = new List<CodeCallCount>(); | 1645 @reflectable final callees = new List<CodeCallCount>(); |
| 1538 @reflectable final instructions = new ObservableList<CodeInstruction>(); | 1646 @reflectable final instructions = new ObservableList<CodeInstruction>(); |
| 1539 @reflectable final addressTicks = new ObservableMap<int, CodeTick>(); | 1647 @reflectable final addressTicks = new ObservableMap<int, CodeTick>(); |
| 1540 @observable String formattedInclusiveTicks = ''; | 1648 @observable String formattedInclusiveTicks = ''; |
| 1541 @observable String formattedExclusiveTicks = ''; | 1649 @observable String formattedExclusiveTicks = ''; |
| 1542 @observable ServiceMap objectPool; | 1650 @observable ServiceMap objectPool; |
| 1543 @observable ServiceMap function; | 1651 @observable Function function; |
| 1544 @observable Script script; | 1652 @observable Script script; |
| 1545 @observable bool isOptimized = false; | 1653 @observable bool isOptimized = false; |
| 1546 String name; | 1654 String name; |
| 1547 String vmName; | 1655 String vmName; |
| 1548 | 1656 |
| 1549 bool get canCache => true; | 1657 bool get canCache => true; |
| 1550 bool get immutable => true; | 1658 bool get immutable => true; |
| 1551 | 1659 |
| 1552 Code._empty(ServiceObjectOwner owner) : super._empty(owner); | 1660 Code._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 1553 | 1661 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1576 if (script != null) { | 1684 if (script != null) { |
| 1577 // Already done. | 1685 // Already done. |
| 1578 return; | 1686 return; |
| 1579 } | 1687 } |
| 1580 if (kind != CodeKind.Dart){ | 1688 if (kind != CodeKind.Dart){ |
| 1581 return; | 1689 return; |
| 1582 } | 1690 } |
| 1583 if (function == null) { | 1691 if (function == null) { |
| 1584 return; | 1692 return; |
| 1585 } | 1693 } |
| 1586 if (function['script'] == null) { | 1694 if (function.script == null) { |
| 1587 // Attempt to load the function. | 1695 // Attempt to load the function. |
| 1588 function.load().then((func) { | 1696 function.load().then((func) { |
| 1589 var script = function['script']; | 1697 var script = function.script; |
| 1590 if (script == null) { | 1698 if (script == null) { |
| 1591 // Function doesn't have an associated script. | 1699 // Function doesn't have an associated script. |
| 1592 return; | 1700 return; |
| 1593 } | 1701 } |
| 1594 // Load the script and then update descriptors. | 1702 // Load the script and then update descriptors. |
| 1595 script.load().then(_updateDescriptors); | 1703 script.load().then(_updateDescriptors); |
| 1596 }); | 1704 }); |
| 1597 return; | 1705 return; |
| 1598 } | 1706 } |
| 1599 // Load the script and then update descriptors. | 1707 // Load the script and then update descriptors. |
| 1600 function['script'].load().then(_updateDescriptors); | 1708 function.script.load().then(_updateDescriptors); |
| 1601 } | 1709 } |
| 1602 | 1710 |
| 1603 /// Reload [this]. Returns a future which completes to [this] or | 1711 /// Reload [this]. Returns a future which completes to [this] or |
| 1604 /// a [ServiceError]. | 1712 /// a [ServiceError]. |
| 1605 Future<ServiceObject> reload() { | 1713 Future<ServiceObject> reload() { |
| 1606 assert(kind != null); | 1714 assert(kind != null); |
| 1607 if (kind == CodeKind.Dart) { | 1715 if (kind == CodeKind.Dart) { |
| 1608 // We only reload Dart code. | 1716 // We only reload Dart code. |
| 1609 return super.reload(); | 1717 return super.reload(); |
| 1610 } | 1718 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1916 var v = list[i]; | 2024 var v = list[i]; |
| 1917 if ((v is ObservableMap) && _isServiceMap(v)) { | 2025 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 1918 list[i] = owner.getFromMap(v); | 2026 list[i] = owner.getFromMap(v); |
| 1919 } else if (v is ObservableList) { | 2027 } else if (v is ObservableList) { |
| 1920 _upgradeObservableList(v, owner); | 2028 _upgradeObservableList(v, owner); |
| 1921 } else if (v is ObservableMap) { | 2029 } else if (v is ObservableMap) { |
| 1922 _upgradeObservableMap(v, owner); | 2030 _upgradeObservableMap(v, owner); |
| 1923 } | 2031 } |
| 1924 } | 2032 } |
| 1925 } | 2033 } |
| OLD | NEW |