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

Side by Side Diff: runtime/vm/isolate.cc

Issue 16077018: Implemented an averaging object histogram in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "platform/json.h" 9 #include "platform/json.h"
10 #include "lib/mirrors.h" 10 #include "lib/mirrors.h"
11 #include "vm/code_observers.h" 11 #include "vm/code_observers.h"
12 #include "vm/compiler_stats.h" 12 #include "vm/compiler_stats.h"
13 #include "vm/dart_api_state.h" 13 #include "vm/dart_api_state.h"
14 #include "vm/dart_entry.h" 14 #include "vm/dart_entry.h"
15 #include "vm/debugger.h" 15 #include "vm/debugger.h"
16 #include "vm/heap.h" 16 #include "vm/heap.h"
17 #include "vm/heap_histogram.h"
17 #include "vm/message_handler.h" 18 #include "vm/message_handler.h"
18 #include "vm/object_store.h" 19 #include "vm/object_store.h"
19 #include "vm/parser.h" 20 #include "vm/parser.h"
20 #include "vm/port.h" 21 #include "vm/port.h"
21 #include "vm/simulator.h" 22 #include "vm/simulator.h"
22 #include "vm/stack_frame.h" 23 #include "vm/stack_frame.h"
23 #include "vm/stub_code.h" 24 #include "vm/stub_code.h"
24 #include "vm/symbols.h" 25 #include "vm/symbols.h"
25 #include "vm/thread.h" 26 #include "vm/thread.h"
26 #include "vm/timer.h" 27 #include "vm/timer.h"
27 #include "vm/visitor.h" 28 #include "vm/visitor.h"
28 29
29 namespace dart { 30 namespace dart {
30 31
31 DEFINE_FLAG(bool, report_usage_count, false, 32 DEFINE_FLAG(bool, report_usage_count, false,
32 "Track function usage and report."); 33 "Track function usage and report.");
33 DEFINE_FLAG(bool, trace_isolates, false, 34 DEFINE_FLAG(bool, trace_isolates, false,
34 "Trace isolate creation and shut down."); 35 "Trace isolate creation and shut down.");
35 DECLARE_FLAG(bool, trace_deoptimization_verbose); 36 DECLARE_FLAG(bool, trace_deoptimization_verbose);
36 37
38
39 void Isolate::RegisterClass(const Class& cls) {
40 class_table()->Register(cls);
41 if (object_histogram() != NULL) object_histogram()->RegisterClass(cls);
42 }
43
44
37 class IsolateMessageHandler : public MessageHandler { 45 class IsolateMessageHandler : public MessageHandler {
38 public: 46 public:
39 explicit IsolateMessageHandler(Isolate* isolate); 47 explicit IsolateMessageHandler(Isolate* isolate);
40 ~IsolateMessageHandler(); 48 ~IsolateMessageHandler();
41 49
42 const char* name() const; 50 const char* name() const;
43 void MessageNotify(Message::Priority priority); 51 void MessageNotify(Message::Priority priority);
44 bool HandleMessage(Message* message); 52 bool HandleMessage(Message* message);
45 53
46 #if defined(DEBUG) 54 #if defined(DEBUG)
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 OS::PrintErr(" %s <- %s\n", 364 OS::PrintErr(" %s <- %s\n",
357 String::Handle(field.name()).ToCString(), 365 String::Handle(field.name()).ToCString(),
358 value.ToCString()); 366 value.ToCString());
359 } 367 }
360 } 368 }
361 369
362 object_ = &obj; 370 object_ = &obj;
363 } 371 }
364 372
365 373
366 Isolate::Isolate() 374 Isolate::Isolate(bool is_vm_isolate)
367 : store_buffer_(), 375 : store_buffer_(),
368 message_notify_callback_(NULL), 376 message_notify_callback_(NULL),
369 name_(NULL), 377 name_(NULL),
370 start_time_(OS::GetCurrentTimeMicros()), 378 start_time_(OS::GetCurrentTimeMicros()),
371 main_port_(0), 379 main_port_(0),
372 heap_(NULL), 380 heap_(NULL),
373 object_store_(NULL), 381 object_store_(NULL),
374 top_context_(Context::null()), 382 top_context_(Context::null()),
375 top_exit_frame_info_(0), 383 top_exit_frame_info_(0),
376 init_callback_data_(NULL), 384 init_callback_data_(NULL),
(...skipping 16 matching lines...) Expand all
393 gc_epilogue_callbacks_(), 401 gc_epilogue_callbacks_(),
394 deopt_cpu_registers_copy_(NULL), 402 deopt_cpu_registers_copy_(NULL),
395 deopt_fpu_registers_copy_(NULL), 403 deopt_fpu_registers_copy_(NULL),
396 deopt_frame_copy_(NULL), 404 deopt_frame_copy_(NULL),
397 deopt_frame_copy_size_(0), 405 deopt_frame_copy_size_(0),
398 deferred_boxes_(NULL), 406 deferred_boxes_(NULL),
399 deferred_object_refs_(NULL), 407 deferred_object_refs_(NULL),
400 deferred_objects_count_(0), 408 deferred_objects_count_(0),
401 deferred_objects_(NULL), 409 deferred_objects_(NULL),
402 stacktrace_(NULL), 410 stacktrace_(NULL),
403 stack_frame_index_(-1) { 411 stack_frame_index_(-1),
412 object_histogram_(NULL) {
413 if (FLAG_print_object_histogram && !is_vm_isolate) {
Ivan Posva 2013/06/12 15:18:09 if (FLAG_print_object_histogram && (Dart::vm_isol
bakster 2013/06/12 15:42:42 Seems flaky to me but, I'll change it. On 2013/06
414 object_histogram_ = new ObjectHistogram(this);
415 }
404 } 416 }
405 417
406 418
407 Isolate::~Isolate() { 419 Isolate::~Isolate() {
408 delete [] name_; 420 delete [] name_;
409 delete heap_; 421 delete heap_;
410 delete object_store_; 422 delete object_store_;
411 delete api_state_; 423 delete api_state_;
412 delete stub_code_; 424 delete stub_code_;
413 delete debugger_; 425 delete debugger_;
414 #if defined(USING_SIMULATOR) 426 #if defined(USING_SIMULATOR)
415 delete simulator_; 427 delete simulator_;
416 #endif 428 #endif
417 delete mutex_; 429 delete mutex_;
418 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. 430 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
419 delete message_handler_; 431 delete message_handler_;
420 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 432 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
433 delete object_histogram_;
421 } 434 }
422 435
423 void Isolate::SetCurrent(Isolate* current) { 436 void Isolate::SetCurrent(Isolate* current) {
424 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); 437 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
425 } 438 }
426 439
427 440
428 // The single thread local key which stores all the thread local data 441 // The single thread local key which stores all the thread local data
429 // for a thread. Since an Isolate is the central repository for 442 // for a thread. Since an Isolate is the central repository for
430 // storing all isolate specific information a single thread local key 443 // storing all isolate specific information a single thread local key
431 // is sufficient. 444 // is sufficient.
432 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey; 445 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey;
433 446
434 447
435 void Isolate::InitOnce() { 448 void Isolate::InitOnce() {
436 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey); 449 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey);
437 isolate_key = Thread::CreateThreadLocal(); 450 isolate_key = Thread::CreateThreadLocal();
438 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey); 451 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey);
439 create_callback_ = NULL; 452 create_callback_ = NULL;
440 } 453 }
441 454
442 455
443 Isolate* Isolate::Init(const char* name_prefix) { 456 Isolate* Isolate::Init(const char* name_prefix, bool is_vm_isolate) {
444 Isolate* result = new Isolate(); 457 Isolate* result = new Isolate(is_vm_isolate);
445 ASSERT(result != NULL); 458 ASSERT(result != NULL);
446 459
447 // TODO(5411455): For now just set the recently created isolate as 460 // TODO(5411455): For now just set the recently created isolate as
448 // the current isolate. 461 // the current isolate.
449 SetCurrent(result); 462 SetCurrent(result);
450 463
451 // Setup the isolate message handler. 464 // Setup the isolate message handler.
452 MessageHandler* handler = new IsolateMessageHandler(result); 465 MessageHandler* handler = new IsolateMessageHandler(result);
453 ASSERT(handler != NULL); 466 ASSERT(handler != NULL);
454 result->set_message_handler(handler); 467 result->set_message_handler(handler);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 private: 735 private:
723 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); 736 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor);
724 }; 737 };
725 738
726 739
727 void Isolate::Shutdown() { 740 void Isolate::Shutdown() {
728 ASSERT(this == Isolate::Current()); 741 ASSERT(this == Isolate::Current());
729 ASSERT(top_resource() == NULL); 742 ASSERT(top_resource() == NULL);
730 ASSERT((heap_ == NULL) || heap_->Verify()); 743 ASSERT((heap_ == NULL) || heap_->Verify());
731 744
745 if (FLAG_print_object_histogram) {
746 StackZone stack_zone(this);
Ivan Posva 2013/06/12 15:18:09 Please move the HandleScope from within Print here
bakster 2013/06/12 15:42:42 Done.
747 heap()->CollectAllGarbage();
748 object_histogram()->Print();
749 }
750
732 // Clean up debugger resources. Shutting down the debugger 751 // Clean up debugger resources. Shutting down the debugger
733 // requires a handle zone. We must set up a temporary zone because 752 // requires a handle zone. We must set up a temporary zone because
734 // Isolate::Shutdown is called without a zone. 753 // Isolate::Shutdown is called without a zone.
735 { 754 {
736 StackZone zone(this); 755 StackZone zone(this);
737 HandleScope handle_scope(this); 756 HandleScope handle_scope(this);
738 debugger_->Shutdown(); 757 debugger_->Shutdown();
739 } 758 }
740 759
741 // Close all the ports owned by this isolate. 760 // Close all the ports owned by this isolate.
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return func.raw(); 1157 return func.raw();
1139 } 1158 }
1140 1159
1141 1160
1142 void IsolateSpawnState::Cleanup() { 1161 void IsolateSpawnState::Cleanup() {
1143 SwitchIsolateScope switch_scope(isolate()); 1162 SwitchIsolateScope switch_scope(isolate());
1144 Dart::ShutdownIsolate(); 1163 Dart::ShutdownIsolate();
1145 } 1164 }
1146 1165
1147 } // namespace dart 1166 } // namespace dart
OLDNEW
« runtime/vm/isolate.h ('K') | « runtime/vm/isolate.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698