OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// This library defines runtime operations on objects used by the code | 5 /// This library defines runtime operations on objects used by the code |
6 /// generator. | 6 /// generator. |
7 part of dart._runtime; | 7 part of dart._runtime; |
8 | 8 |
9 class InvocationImpl extends Invocation { | 9 class InvocationImpl extends Invocation { |
10 final Symbol memberName; | 10 final Symbol memberName; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 obj, field, (resolvedField) => dput(obj, resolvedField, value)); | 354 obj, field, (resolvedField) => dput(obj, resolvedField, value)); |
355 | 355 |
356 _callMethodRepl(obj, method, typeArgs, args) => _dhelperRepl(obj, method, | 356 _callMethodRepl(obj, method, typeArgs, args) => _dhelperRepl(obj, method, |
357 (resolvedField) => _callMethod(obj, resolvedField, typeArgs, args, method)); | 357 (resolvedField) => _callMethod(obj, resolvedField, typeArgs, args, method)); |
358 | 358 |
359 dsendRepl(obj, method, @rest args) => _callMethodRepl(obj, method, null, args); | 359 dsendRepl(obj, method, @rest args) => _callMethodRepl(obj, method, null, args); |
360 | 360 |
361 dgsendRepl(obj, typeArgs, method, @rest args) => | 361 dgsendRepl(obj, typeArgs, method, @rest args) => |
362 _callMethodRepl(obj, method, typeArgs, args); | 362 _callMethodRepl(obj, method, typeArgs, args); |
363 | 363 |
364 class _MethodStats { | |
365 final String typeName; | |
366 final String frame; | |
367 int count; | |
368 | |
369 _MethodStats(this.typeName, this.frame) { | |
370 count = 0; | |
371 } | |
372 } | |
373 | |
374 Map<String, _MethodStats> _callMethodStats = new Map(); | |
375 | |
376 List<List<Object>> getDynamicStats() { | |
377 List<List<Object>> ret = []; | |
378 | |
379 var keys = _callMethodStats.keys.toList(); | |
380 | |
381 keys.sort( | |
382 (a, b) => _callMethodStats[b].count.compareTo(_callMethodStats[a].count)); | |
383 for (var key in keys) { | |
384 var stats = _callMethodStats[key]; | |
385 ret.add([stats.typeName, stats.frame, stats.count]); | |
386 } | |
387 | |
388 return ret; | |
389 } | |
390 | |
391 clearDynamicStats() { | |
392 _callMethodStats.clear(); | |
393 } | |
394 | |
395 bool trackProfile = JS('bool', 'dart.global.trackDdcProfile'); | |
396 | |
397 _trackCall(obj) { | |
398 if (JS('bool', '!#', trackProfile)) return; | |
399 | |
400 var actual = getReifiedType(obj); | |
401 String stackStr = JS('String', "new Error().stack"); | |
402 var stack = stackStr.split('\n at '); | |
403 var src = ''; | |
404 for (int i = 2; i < stack.length; ++i) { | |
405 var frame = stack[i]; | |
406 if (!frame.contains('dart_sdk.js')) { | |
407 src = frame; | |
408 break; | |
409 } | |
410 } | |
411 | |
412 var actualTypeName = typeName(actual); | |
413 _callMethodStats | |
414 .putIfAbsent( | |
415 "$actualTypeName <$src>", () => new _MethodStats(actualTypeName, src)) | |
416 .count++; | |
417 } | |
418 | |
419 /// Shared code for dsend, dindex, and dsetindex. | 364 /// Shared code for dsend, dindex, and dsetindex. |
420 _callMethod(obj, name, typeArgs, args, displayName) { | 365 _callMethod(obj, name, typeArgs, args, displayName) { |
421 var symbol = _canonicalMember(obj, name); | 366 var symbol = _canonicalMember(obj, name); |
422 if (symbol == null) { | 367 if (symbol == null) { |
423 return noSuchMethod( | 368 return noSuchMethod( |
424 obj, new InvocationImpl(displayName, args, isMethod: true)); | 369 obj, new InvocationImpl(displayName, args, isMethod: true)); |
425 } | 370 } |
426 var f = obj != null ? JS('', '#[#]', obj, symbol) : null; | 371 var f = obj != null ? JS('', '#[#]', obj, symbol) : null; |
427 var type = getType(obj); | 372 var type = getType(obj); |
428 var ftype = getMethodType(type, symbol); | 373 var ftype = getMethodType(type, symbol); |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 name = '+' + name; | 928 name = '+' + name; |
984 } | 929 } |
985 return name; | 930 return name; |
986 } | 931 } |
987 | 932 |
988 /// Emulates the implicit "loadLibrary" function provided by a deferred library. | 933 /// Emulates the implicit "loadLibrary" function provided by a deferred library. |
989 /// | 934 /// |
990 /// Libraries are not actually deferred in DDC, so this just returns a future | 935 /// Libraries are not actually deferred in DDC, so this just returns a future |
991 /// that completes immediately. | 936 /// that completes immediately. |
992 Future loadLibrary() => new Future.value(); | 937 Future loadLibrary() => new Future.value(); |
OLD | NEW |