OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/bigint_store.h" | 9 #include "vm/bigint_store.h" |
10 #include "vm/code_index_table.h" | 10 #include "vm/code_index_table.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if ((*a)->invocation_counter() > (*b)->invocation_counter()) { | 257 if ((*a)->invocation_counter() > (*b)->invocation_counter()) { |
258 return -1; | 258 return -1; |
259 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) { | 259 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) { |
260 return 1; | 260 return 1; |
261 } else { | 261 } else { |
262 return 0; | 262 return 0; |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 | 266 |
| 267 static void AddFunctionsFromClass(const Class& cls, |
| 268 GrowableArray<const Function*>* functions) { |
| 269 const Array& class_functions = Array::Handle(cls.functions()); |
| 270 // Class 'Dynamic' is allocated/initialized in a special way, leaving |
| 271 // the functions field NULL instead of empty. |
| 272 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); |
| 273 for (int j = 0; j < func_len; j++) { |
| 274 Function& function = Function::Handle(); |
| 275 function ^= class_functions.At(j); |
| 276 if (function.invocation_counter() > 0) { |
| 277 functions->Add(&function); |
| 278 } |
| 279 } |
| 280 } |
| 281 |
| 282 |
267 void Isolate::PrintInvokedFunctions() { | 283 void Isolate::PrintInvokedFunctions() { |
268 ASSERT(this == Isolate::Current()); | 284 ASSERT(this == Isolate::Current()); |
269 Zone zone(this); | 285 Zone zone(this); |
270 HandleScope handle_scope(this); | 286 HandleScope handle_scope(this); |
271 Library& library = Library::Handle(); | 287 Library& library = Library::Handle(); |
272 library = object_store()->registered_libraries(); | 288 library = object_store()->registered_libraries(); |
273 GrowableArray<const Function*> invoked_functions; | 289 GrowableArray<const Function*> invoked_functions; |
274 while (!library.IsNull()) { | 290 while (!library.IsNull()) { |
275 Class& cls = Class::Handle(); | 291 Class& cls = Class::Handle(); |
276 ClassDictionaryIterator iter(library); | 292 ClassDictionaryIterator iter(library); |
277 while (iter.HasNext()) { | 293 while (iter.HasNext()) { |
278 cls = iter.GetNextClass(); | 294 cls = iter.GetNextClass(); |
279 const Array& functions = Array::Handle(cls.functions()); | 295 AddFunctionsFromClass(cls, &invoked_functions); |
280 // Class 'Dynamic' is allocated/initialized in a special way, leaving | 296 } |
281 // the functions field NULL instead of empty. | 297 Array& anon_classes = Array::Handle(library.raw_ptr()->anonymous_classes_); |
282 const int func_len = functions.IsNull() ? 0 : functions.Length(); | 298 for (int i = 0; i < library.raw_ptr()->num_anonymous_; i++) { |
283 for (int j = 0; j < func_len; j++) { | 299 cls ^= anon_classes.At(i); |
284 Function& function = Function::Handle(); | 300 AddFunctionsFromClass(cls, &invoked_functions); |
285 function ^= functions.At(j); | |
286 if (function.invocation_counter() > 0) { | |
287 invoked_functions.Add(&function); | |
288 } | |
289 } | |
290 } | 301 } |
291 library = library.next_registered(); | 302 library = library.next_registered(); |
292 } | 303 } |
293 invoked_functions.Sort(MostCalledFunctionFirst); | 304 invoked_functions.Sort(MostCalledFunctionFirst); |
294 for (int i = 0; i < invoked_functions.length(); i++) { | 305 for (int i = 0; i < invoked_functions.length(); i++) { |
295 OS::Print("%10d x %s\n", | 306 OS::Print("%10d x %s\n", |
296 invoked_functions[i]->invocation_counter(), | 307 invoked_functions[i]->invocation_counter(), |
297 invoked_functions[i]->ToFullyQualifiedCString()); | 308 invoked_functions[i]->ToFullyQualifiedCString()); |
298 } | 309 } |
299 } | 310 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 464 } |
454 | 465 |
455 | 466 |
456 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor) { | 467 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor) { |
457 if (api_state() != NULL) { | 468 if (api_state() != NULL) { |
458 api_state()->VisitWeakHandles(visitor); | 469 api_state()->VisitWeakHandles(visitor); |
459 } | 470 } |
460 } | 471 } |
461 | 472 |
462 } // namespace dart | 473 } // namespace dart |
OLD | NEW |