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

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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 362
355 if (FLAG_trace_deoptimization_verbose) { 363 if (FLAG_trace_deoptimization_verbose) {
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
ahe 2013/06/12 11:24:01 Add extra line.
bakster 2013/06/12 11:34:21 Done.
365 373 Isolate::Isolate(bool is_vm_isolate)
366 Isolate::Isolate()
367 : store_buffer_(), 374 : store_buffer_(),
368 message_notify_callback_(NULL), 375 message_notify_callback_(NULL),
369 name_(NULL), 376 name_(NULL),
370 start_time_(OS::GetCurrentTimeMicros()), 377 start_time_(OS::GetCurrentTimeMicros()),
371 main_port_(0), 378 main_port_(0),
372 heap_(NULL), 379 heap_(NULL),
373 object_store_(NULL), 380 object_store_(NULL),
374 top_context_(Context::null()), 381 top_context_(Context::null()),
375 top_exit_frame_info_(0), 382 top_exit_frame_info_(0),
376 init_callback_data_(NULL), 383 init_callback_data_(NULL),
(...skipping 16 matching lines...) Expand all
393 gc_epilogue_callbacks_(), 400 gc_epilogue_callbacks_(),
394 deopt_cpu_registers_copy_(NULL), 401 deopt_cpu_registers_copy_(NULL),
395 deopt_fpu_registers_copy_(NULL), 402 deopt_fpu_registers_copy_(NULL),
396 deopt_frame_copy_(NULL), 403 deopt_frame_copy_(NULL),
397 deopt_frame_copy_size_(0), 404 deopt_frame_copy_size_(0),
398 deferred_boxes_(NULL), 405 deferred_boxes_(NULL),
399 deferred_object_refs_(NULL), 406 deferred_object_refs_(NULL),
400 deferred_objects_count_(0), 407 deferred_objects_count_(0),
401 deferred_objects_(NULL), 408 deferred_objects_(NULL),
402 stacktrace_(NULL), 409 stacktrace_(NULL),
403 stack_frame_index_(-1) { 410 stack_frame_index_(-1),
411 object_histogram_(NULL) {
412 if (FLAG_print_object_histogram && !is_vm_isolate) {
413 object_histogram_ = new ObjectHistogram(this);
414 }
404 } 415 }
405 416
406 417
407 Isolate::~Isolate() { 418 Isolate::~Isolate() {
408 delete [] name_; 419 delete [] name_;
409 delete heap_; 420 delete heap_;
410 delete object_store_; 421 delete object_store_;
411 delete api_state_; 422 delete api_state_;
412 delete stub_code_; 423 delete stub_code_;
413 delete debugger_; 424 delete debugger_;
414 #if defined(USING_SIMULATOR) 425 #if defined(USING_SIMULATOR)
415 delete simulator_; 426 delete simulator_;
416 #endif 427 #endif
417 delete mutex_; 428 delete mutex_;
418 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. 429 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
419 delete message_handler_; 430 delete message_handler_;
420 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 431 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
432 delete object_histogram_;
421 } 433 }
422 434
423 void Isolate::SetCurrent(Isolate* current) { 435 void Isolate::SetCurrent(Isolate* current) {
424 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); 436 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
425 } 437 }
426 438
427 439
428 // The single thread local key which stores all the thread local data 440 // The single thread local key which stores all the thread local data
429 // for a thread. Since an Isolate is the central repository for 441 // for a thread. Since an Isolate is the central repository for
430 // storing all isolate specific information a single thread local key 442 // storing all isolate specific information a single thread local key
431 // is sufficient. 443 // is sufficient.
432 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey; 444 ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey;
433 445
434 446
435 void Isolate::InitOnce() { 447 void Isolate::InitOnce() {
436 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey); 448 ASSERT(isolate_key == Thread::kUnsetThreadLocalKey);
437 isolate_key = Thread::CreateThreadLocal(); 449 isolate_key = Thread::CreateThreadLocal();
438 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey); 450 ASSERT(isolate_key != Thread::kUnsetThreadLocalKey);
439 create_callback_ = NULL; 451 create_callback_ = NULL;
440 } 452 }
441 453
442 454
443 Isolate* Isolate::Init(const char* name_prefix) { 455 Isolate* Isolate::Init(const char* name_prefix, bool is_vm_isolate) {
444 Isolate* result = new Isolate(); 456 Isolate* result = new Isolate(is_vm_isolate);
445 ASSERT(result != NULL); 457 ASSERT(result != NULL);
446 458
447 // TODO(5411455): For now just set the recently created isolate as 459 // TODO(5411455): For now just set the recently created isolate as
448 // the current isolate. 460 // the current isolate.
449 SetCurrent(result); 461 SetCurrent(result);
450 462
451 // Setup the isolate message handler. 463 // Setup the isolate message handler.
452 MessageHandler* handler = new IsolateMessageHandler(result); 464 MessageHandler* handler = new IsolateMessageHandler(result);
453 ASSERT(handler != NULL); 465 ASSERT(handler != NULL);
454 result->set_message_handler(handler); 466 result->set_message_handler(handler);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 private: 734 private:
723 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); 735 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor);
724 }; 736 };
725 737
726 738
727 void Isolate::Shutdown() { 739 void Isolate::Shutdown() {
728 ASSERT(this == Isolate::Current()); 740 ASSERT(this == Isolate::Current());
729 ASSERT(top_resource() == NULL); 741 ASSERT(top_resource() == NULL);
730 ASSERT((heap_ == NULL) || heap_->Verify()); 742 ASSERT((heap_ == NULL) || heap_->Verify());
731 743
744 if (FLAG_print_object_histogram) {
745 StackZone stack_zone(this);
746 heap()->CollectAllGarbage();
747 object_histogram()->Print();
748 }
749
732 // Clean up debugger resources. Shutting down the debugger 750 // Clean up debugger resources. Shutting down the debugger
733 // requires a handle zone. We must set up a temporary zone because 751 // requires a handle zone. We must set up a temporary zone because
734 // Isolate::Shutdown is called without a zone. 752 // Isolate::Shutdown is called without a zone.
735 { 753 {
736 StackZone zone(this); 754 StackZone zone(this);
737 HandleScope handle_scope(this); 755 HandleScope handle_scope(this);
738 debugger_->Shutdown(); 756 debugger_->Shutdown();
739 } 757 }
740 758
741 // Close all the ports owned by this isolate. 759 // Close all the ports owned by this isolate.
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return func.raw(); 1156 return func.raw();
1139 } 1157 }
1140 1158
1141 1159
1142 void IsolateSpawnState::Cleanup() { 1160 void IsolateSpawnState::Cleanup() {
1143 SwitchIsolateScope switch_scope(isolate()); 1161 SwitchIsolateScope switch_scope(isolate());
1144 Dart::ShutdownIsolate(); 1162 Dart::ShutdownIsolate();
1145 } 1163 }
1146 1164
1147 } // namespace dart 1165 } // namespace dart
OLDNEW
« runtime/vm/heap_histogram.cc ('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