Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: runtime/bin/vmservice/client/lib/src/service/cache.dart

Issue 197803004: Add dead CodeRegionTable for tracking overwritten Dart code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /// Abstract [ServiceObjectCache]. 7 /// Abstract [ServiceObjectCache].
8 abstract class ServiceObjectCache<T extends ServiceObject> { 8 abstract class ServiceObjectCache<T extends ServiceObject> {
9 final Isolate isolate; 9 final Isolate isolate;
10 final _cache = new ObservableMap<String, T>(); 10 final _cache = new ObservableMap<String, T>();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 return isolate.get(id).then(_addToCache); 47 return isolate.get(id).then(_addToCache);
48 } 48 }
49 49
50 /// If [obj] is cached, return the cached object. Otherwise, upgrades [obj] 50 /// If [obj] is cached, return the cached object. Otherwise, upgrades [obj]
51 /// and adds the upgraded value to the cache. 51 /// and adds the upgraded value to the cache.
52 T putIfAbsent(ObservableMap obj) { 52 T putIfAbsent(ObservableMap obj) {
53 assert(ServiceObject.isServiceMap(obj)); 53 assert(ServiceObject.isServiceMap(obj));
54 String id = obj['id']; 54 String id = obj['id'];
55 var type = obj['type']; 55 var type = obj['type'];
56 if (!cachesId(id)) {
57 Logger.root.warning('Cache does not cache this id: $id');
58 }
56 assert(cachesId(id)); 59 assert(cachesId(id));
57 if (contains(id)) { 60 if (contains(id)) {
58 return this[id]; 61 return this[id];
59 } 62 }
60 return _addToCache(_upgrade(obj)); 63 return _addToCache(_upgrade(obj));
61 } 64 }
62 65
63 T _addToCache(T so) { 66 T _addToCache(T so) {
64 this[so.id] = so; 67 this[so.id] = so;
65 return so; 68 return so;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return codeList; 113 return codeList;
111 } 114 }
112 115
113 void _resetProfileData() { 116 void _resetProfileData() {
114 _cache.forEach((k, Code code) { 117 _cache.forEach((k, Code code) {
115 code.resetProfileData(); 118 code.resetProfileData();
116 }); 119 });
117 } 120 }
118 121
119 void _updateProfileData(ServiceMap profile, List<Code> codeTable) { 122 void _updateProfileData(ServiceMap profile, List<Code> codeTable) {
120 var codes = profile['codes']; 123 var codeRegions = profile['codes'];
121 var sampleCount = profile['samples']; 124 var sampleCount = profile['samples'];
122 for (var profileCode in codes) { 125 for (var codeRegion in codeRegions) {
123 Code code = profileCode['code']; 126 Code code = codeRegion['code'];
124 code.updateProfileData(profileCode, codeTable, sampleCount); 127 code.updateProfileData(codeRegion, codeTable, sampleCount);
125 } 128 }
126 } 129 }
127 } 130 }
128 131
129 class ClassCache extends ServiceObjectCache<ServiceMap> { 132 class ClassCache extends ServiceObjectCache<ServiceMap> {
130 ClassCache(Isolate isolate) : super(isolate); 133 ClassCache(Isolate isolate) : super(isolate);
131 134
132 bool cachesId(String id) => _matcher.hasMatch(id); 135 bool cachesId(String id) => _matcher.hasMatch(id);
133 bool cachesType(String type) => ServiceObject.stripRef(type) == 'Class'; 136 bool cachesType(String type) => ServiceObject.stripRef(type) == 'Class';
134 ServiceMap _upgrade(ObservableMap obj) => 137 ServiceMap _upgrade(ObservableMap obj) =>
135 new ServiceMap.fromMap(isolate, obj); 138 new ServiceMap.fromMap(isolate, obj);
136 139
137 static final RegExp _matcher = new RegExp(r'classes/\d+$'); 140 static final RegExp _matcher = new RegExp(r'classes/\d+$');
138 } 141 }
142
143 class FunctionCache extends ServiceObjectCache<ServiceMap> {
144 FunctionCache(Isolate isolate) : super(isolate);
145
146 bool cachesId(String id) => _native_matcher.hasMatch(id) ||
147 _collected_matcher.hasMatch(id) ||
148 _reused_matcher.hasMatch(id) ||
149 _stub_matcher.hasMatch(id) ||
150 _class_function_matcher.hasMatch(id) ||
151 _class_closure_matcher.hasMatch(id) ||
152 _class_implicit_closure_matcher.hasMatch(id) ||
153 _class_dispatcher_matcher.hasMatch(id);
turnidge 2014/03/13 18:09:09 Checking 8 regexps will be slower than checking 1
Cutch 2014/03/13 20:52:26 Done.
154
155 bool cachesType(String type) => ServiceObject.stripRef(type) == 'Function';
156 ServiceMap _upgrade(ObservableMap obj) =>
157 new ServiceMap.fromMap(isolate, obj);
158
159 static final RegExp _native_matcher = new RegExp(r'^functions/native-.+');
160 static final RegExp _collected_matcher =
161 new RegExp(r'^functions/collected-.+');
162 static final RegExp _reused_matcher =
163 new RegExp(r'^functions/reused-.+');
164 static final RegExp _stub_matcher =
165 new RegExp(r'^functions/stub-.+');
166 static final RegExp _class_function_matcher =
167 new RegExp(r'^classes/\d+/functions/.+');
168 static final RegExp _class_closure_matcher =
169 new RegExp(r'^classes/\d+/closures/.+');
170 static final RegExp _class_implicit_closure_matcher =
171 new RegExp(r'^classes/\d+/implicit_closures/.+');
172 static final RegExp _class_dispatcher_matcher =
173 new RegExp(r'^classes/\d+/dispatchers/.+');
174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698