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" |
11 #include "vm/compiler_stats.h" | 11 #include "vm/compiler_stats.h" |
12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
14 #include "vm/debugger.h" | 14 #include "vm/debugger.h" |
15 #include "vm/debuginfo.h" | 15 #include "vm/debuginfo.h" |
16 #include "vm/heap.h" | 16 #include "vm/heap.h" |
17 #include "vm/message.h" | 17 #include "vm/message.h" |
18 #include "vm/object_store.h" | 18 #include "vm/object_store.h" |
19 #include "vm/parser.h" | 19 #include "vm/parser.h" |
20 #include "vm/port.h" | 20 #include "vm/port.h" |
21 #include "vm/random.h" | 21 #include "vm/random.h" |
22 #include "vm/stack_frame.h" | 22 #include "vm/stack_frame.h" |
23 #include "vm/stub_code.h" | 23 #include "vm/stub_code.h" |
24 #include "vm/thread.h" | 24 #include "vm/thread.h" |
25 #include "vm/timer.h" | 25 #include "vm/timer.h" |
26 #include "vm/visitor.h" | 26 #include "vm/visitor.h" |
27 | 27 |
28 namespace dart { | 28 namespace dart { |
29 | 29 |
30 DEFINE_FLAG(bool, report_invocation_count, false, | 30 DEFINE_FLAG(bool, report_usage_count, false, |
31 "Count function invocations and report."); | 31 "Track function usage and report."); |
32 DEFINE_FLAG(bool, trace_isolates, false, | 32 DEFINE_FLAG(bool, trace_isolates, false, |
33 "Trace isolate creation and shut down."); | 33 "Trace isolate creation and shut down."); |
34 DECLARE_FLAG(bool, generate_gdb_symbols); | 34 DECLARE_FLAG(bool, generate_gdb_symbols); |
35 | 35 |
36 | 36 |
37 class IsolateMessageHandler : public MessageHandler { | 37 class IsolateMessageHandler : public MessageHandler { |
38 public: | 38 public: |
39 explicit IsolateMessageHandler(Isolate* isolate); | 39 explicit IsolateMessageHandler(Isolate* isolate); |
40 ~IsolateMessageHandler(); | 40 ~IsolateMessageHandler(); |
41 | 41 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 MutexLocker ml(mutex_); | 245 MutexLocker ml(mutex_); |
246 if (stack_limit_ == saved_stack_limit_) { | 246 if (stack_limit_ == saved_stack_limit_) { |
247 return 0; // No interrupt was requested. | 247 return 0; // No interrupt was requested. |
248 } | 248 } |
249 uword interrupt_bits = stack_limit_ & kInterruptsMask; | 249 uword interrupt_bits = stack_limit_ & kInterruptsMask; |
250 stack_limit_ = saved_stack_limit_; | 250 stack_limit_ = saved_stack_limit_; |
251 return interrupt_bits; | 251 return interrupt_bits; |
252 } | 252 } |
253 | 253 |
254 | 254 |
255 static int MostCalledFunctionFirst(const Function* const* a, | 255 static int MostUsedFunctionFirst(const Function* const* a, |
256 const Function* const* b) { | 256 const Function* const* b) { |
257 if ((*a)->invocation_counter() > (*b)->invocation_counter()) { | 257 if ((*a)->usage_counter() > (*b)->usage_counter()) { |
258 return -1; | 258 return -1; |
259 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) { | 259 } else if ((*a)->usage_counter() < (*b)->usage_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, | 267 static void AddFunctionsFromClass(const Class& cls, |
268 GrowableArray<const Function*>* functions) { | 268 GrowableArray<const Function*>* functions) { |
269 const Array& class_functions = Array::Handle(cls.functions()); | 269 const Array& class_functions = Array::Handle(cls.functions()); |
270 // Class 'Dynamic' is allocated/initialized in a special way, leaving | 270 // Class 'Dynamic' is allocated/initialized in a special way, leaving |
271 // the functions field NULL instead of empty. | 271 // the functions field NULL instead of empty. |
272 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); | 272 const int func_len = class_functions.IsNull() ? 0 : class_functions.Length(); |
273 for (int j = 0; j < func_len; j++) { | 273 for (int j = 0; j < func_len; j++) { |
274 Function& function = Function::Handle(); | 274 Function& function = Function::Handle(); |
275 function ^= class_functions.At(j); | 275 function ^= class_functions.At(j); |
276 if (function.invocation_counter() > 0) { | 276 if (function.usage_counter() > 0) { |
277 functions->Add(&function); | 277 functions->Add(&function); |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 void Isolate::PrintInvokedFunctions() { | 283 void Isolate::PrintInvokedFunctions() { |
284 ASSERT(this == Isolate::Current()); | 284 ASSERT(this == Isolate::Current()); |
285 Zone zone(this); | 285 Zone zone(this); |
286 HandleScope handle_scope(this); | 286 HandleScope handle_scope(this); |
287 Library& library = Library::Handle(); | 287 Library& library = Library::Handle(); |
288 library = object_store()->registered_libraries(); | 288 library = object_store()->registered_libraries(); |
289 GrowableArray<const Function*> invoked_functions; | 289 GrowableArray<const Function*> invoked_functions; |
290 while (!library.IsNull()) { | 290 while (!library.IsNull()) { |
291 Class& cls = Class::Handle(); | 291 Class& cls = Class::Handle(); |
292 ClassDictionaryIterator iter(library); | 292 ClassDictionaryIterator iter(library); |
293 while (iter.HasNext()) { | 293 while (iter.HasNext()) { |
294 cls = iter.GetNextClass(); | 294 cls = iter.GetNextClass(); |
295 AddFunctionsFromClass(cls, &invoked_functions); | 295 AddFunctionsFromClass(cls, &invoked_functions); |
296 } | 296 } |
297 Array& anon_classes = Array::Handle(library.raw_ptr()->anonymous_classes_); | 297 Array& anon_classes = Array::Handle(library.raw_ptr()->anonymous_classes_); |
298 for (int i = 0; i < library.raw_ptr()->num_anonymous_; i++) { | 298 for (int i = 0; i < library.raw_ptr()->num_anonymous_; i++) { |
299 cls ^= anon_classes.At(i); | 299 cls ^= anon_classes.At(i); |
300 AddFunctionsFromClass(cls, &invoked_functions); | 300 AddFunctionsFromClass(cls, &invoked_functions); |
301 } | 301 } |
302 library = library.next_registered(); | 302 library = library.next_registered(); |
303 } | 303 } |
304 invoked_functions.Sort(MostCalledFunctionFirst); | 304 invoked_functions.Sort(MostUsedFunctionFirst); |
305 for (int i = 0; i < invoked_functions.length(); i++) { | 305 for (int i = 0; i < invoked_functions.length(); i++) { |
306 OS::Print("%10d x %s\n", | 306 OS::Print("%10d x %s\n", |
307 invoked_functions[i]->invocation_counter(), | 307 invoked_functions[i]->usage_counter(), |
308 invoked_functions[i]->ToFullyQualifiedCString()); | 308 invoked_functions[i]->ToFullyQualifiedCString()); |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 | 312 |
313 void Isolate::Shutdown() { | 313 void Isolate::Shutdown() { |
314 ASSERT(this == Isolate::Current()); | 314 ASSERT(this == Isolate::Current()); |
315 ASSERT(top_resource_ == NULL); | 315 ASSERT(top_resource_ == NULL); |
316 ASSERT((heap_ == NULL) || heap_->Verify()); | 316 ASSERT((heap_ == NULL) || heap_->Verify()); |
317 | 317 |
318 // Clean up debugger resources. Shutting down the debugger | 318 // Clean up debugger resources. Shutting down the debugger |
319 // requires a handle zone. We must set up a temporary zone because | 319 // requires a handle zone. We must set up a temporary zone because |
320 // Isolate::Shutdown is called without a zone. | 320 // Isolate::Shutdown is called without a zone. |
321 { | 321 { |
322 Zone zone(this); | 322 Zone zone(this); |
323 HandleScope handle_scope(this); | 323 HandleScope handle_scope(this); |
324 debugger_->Shutdown(); | 324 debugger_->Shutdown(); |
325 } | 325 } |
326 | 326 |
327 // Close all the ports owned by this isolate. | 327 // Close all the ports owned by this isolate. |
328 PortMap::ClosePorts(message_handler()); | 328 PortMap::ClosePorts(message_handler()); |
329 | 329 |
330 // Fail fast if anybody tries to post any more messsages to this isolate. | 330 // Fail fast if anybody tries to post any more messsages to this isolate. |
331 delete message_handler(); | 331 delete message_handler(); |
332 set_message_handler(NULL); | 332 set_message_handler(NULL); |
333 | 333 |
334 // Dump all accumalated timer data for the isolate. | 334 // Dump all accumalated timer data for the isolate. |
335 timer_list_.ReportTimers(); | 335 timer_list_.ReportTimers(); |
336 if (FLAG_report_invocation_count) { | 336 if (FLAG_report_usage_count) { |
337 PrintInvokedFunctions(); | 337 PrintInvokedFunctions(); |
338 } | 338 } |
339 CompilerStats::Print(); | 339 CompilerStats::Print(); |
340 if (FLAG_generate_gdb_symbols) { | 340 if (FLAG_generate_gdb_symbols) { |
341 DebugInfo::UnregisterAllSections(); | 341 DebugInfo::UnregisterAllSections(); |
342 } | 342 } |
343 if (FLAG_trace_isolates) { | 343 if (FLAG_trace_isolates) { |
344 OS::Print("[-] Stopping isolate:\n" | 344 OS::Print("[-] Stopping isolate:\n" |
345 "\tisolate: %s\n", name()); | 345 "\tisolate: %s\n", name()); |
346 } | 346 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 464 } |
465 | 465 |
466 | 466 |
467 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor) { | 467 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor) { |
468 if (api_state() != NULL) { | 468 if (api_state() != NULL) { |
469 api_state()->VisitWeakHandles(visitor); | 469 api_state()->VisitWeakHandles(visitor); |
470 } | 470 } |
471 } | 471 } |
472 | 472 |
473 } // namespace dart | 473 } // namespace dart |
OLD | NEW |