OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_H_ | 5 #ifndef V8_HEAP_H_ |
6 #define V8_HEAP_H_ | 6 #define V8_HEAP_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 540 |
541 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); | 541 DISALLOW_COPY_AND_ASSIGN(ExternalStringTable); |
542 }; | 542 }; |
543 | 543 |
544 | 544 |
545 enum ArrayStorageAllocationMode { | 545 enum ArrayStorageAllocationMode { |
546 DONT_INITIALIZE_ARRAY_ELEMENTS, | 546 DONT_INITIALIZE_ARRAY_ELEMENTS, |
547 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE | 547 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
548 }; | 548 }; |
549 | 549 |
| 550 // TODO(ernstm): Move into GCTracer. |
| 551 // A simple ring buffer class with maximum size known at compile time. |
| 552 // The class only implements the functionality required in GCTracer. |
| 553 template<typename T, size_t MAX_SIZE> |
| 554 class RingBuffer { |
| 555 public: |
| 556 class const_iterator { |
| 557 public: |
| 558 const_iterator() : index_(0), elements_(NULL) {} |
| 559 |
| 560 const_iterator(size_t index, const T* elements) : |
| 561 index_(index), elements_(elements) {} |
| 562 |
| 563 bool operator==(const const_iterator& rhs) const { |
| 564 return elements_ == rhs.elements_ && |
| 565 index_ == rhs.index_; |
| 566 } |
| 567 |
| 568 bool operator!=(const const_iterator& rhs) const { |
| 569 return elements_ != rhs.elements_ || |
| 570 index_ != rhs.index_; |
| 571 } |
| 572 |
| 573 operator const T*() const { |
| 574 return elements_ + index_; |
| 575 } |
| 576 |
| 577 const T* operator->() const { |
| 578 return elements_ + index_; |
| 579 } |
| 580 |
| 581 const T& operator*() const { |
| 582 return elements_[index_]; |
| 583 } |
| 584 |
| 585 const_iterator& operator++() { |
| 586 index_ = (index_ + 1) % (MAX_SIZE + 1); |
| 587 return *this; |
| 588 } |
| 589 |
| 590 const_iterator& operator--() { |
| 591 index_ = (index_ + MAX_SIZE) % (MAX_SIZE + 1); |
| 592 return *this; |
| 593 } |
| 594 |
| 595 private: |
| 596 size_t index_; |
| 597 const T* elements_; |
| 598 }; |
| 599 |
| 600 RingBuffer() : begin_(0), end_(0) {} |
| 601 |
| 602 bool empty() const { return begin_ == end_; } |
| 603 size_t size() const { |
| 604 return (end_ - begin_ + MAX_SIZE + 1) % (MAX_SIZE + 1); |
| 605 } |
| 606 const_iterator begin() const { return const_iterator(begin_, elements_); } |
| 607 const_iterator end() const { return const_iterator(end_, elements_); } |
| 608 const_iterator back() const { return --end(); } |
| 609 void push_back(const T& element) { |
| 610 elements_[end_] = element; |
| 611 end_ = (end_ + 1) % (MAX_SIZE + 1); |
| 612 if (end_ == begin_) |
| 613 begin_ = (begin_ + 1) % (MAX_SIZE + 1); |
| 614 } |
| 615 void push_front(const T& element) { |
| 616 begin_ = (begin_ + MAX_SIZE) % (MAX_SIZE + 1); |
| 617 if (begin_ == end_) |
| 618 end_ = (end_ + MAX_SIZE) % (MAX_SIZE + 1); |
| 619 elements_[begin_] = element; |
| 620 } |
| 621 |
| 622 private: |
| 623 T elements_[MAX_SIZE + 1]; |
| 624 size_t begin_; |
| 625 size_t end_; |
| 626 |
| 627 DISALLOW_COPY_AND_ASSIGN(RingBuffer); |
| 628 }; |
| 629 |
550 | 630 |
551 // GCTracer collects and prints ONE line after each garbage collector | 631 // GCTracer collects and prints ONE line after each garbage collector |
552 // invocation IFF --trace_gc is used. | 632 // invocation IFF --trace_gc is used. |
553 | 633 |
| 634 // TODO(ernstm): Unit tests. Move to separate file. |
554 class GCTracer BASE_EMBEDDED { | 635 class GCTracer BASE_EMBEDDED { |
555 public: | 636 public: |
556 class Scope BASE_EMBEDDED { | 637 class Scope BASE_EMBEDDED { |
557 public: | 638 public: |
558 enum ScopeId { | 639 enum ScopeId { |
559 EXTERNAL, | 640 EXTERNAL, |
560 MC_MARK, | 641 MC_MARK, |
561 MC_SWEEP, | 642 MC_SWEEP, |
562 MC_SWEEP_NEWSPACE, | 643 MC_SWEEP_NEWSPACE, |
563 MC_SWEEP_OLDSPACE, | 644 MC_SWEEP_OLDSPACE, |
(...skipping 14 matching lines...) Expand all Loading... |
578 }; | 659 }; |
579 | 660 |
580 Scope(GCTracer* tracer, ScopeId scope) | 661 Scope(GCTracer* tracer, ScopeId scope) |
581 : tracer_(tracer), | 662 : tracer_(tracer), |
582 scope_(scope) { | 663 scope_(scope) { |
583 start_time_ = base::OS::TimeCurrentMillis(); | 664 start_time_ = base::OS::TimeCurrentMillis(); |
584 } | 665 } |
585 | 666 |
586 ~Scope() { | 667 ~Scope() { |
587 ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. | 668 ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. |
588 tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; | 669 tracer_->current_.scopes[scope_] += |
| 670 base::OS::TimeCurrentMillis() - start_time_; |
589 } | 671 } |
590 | 672 |
591 private: | 673 private: |
592 GCTracer* tracer_; | 674 GCTracer* tracer_; |
593 ScopeId scope_; | 675 ScopeId scope_; |
594 double start_time_; | 676 double start_time_; |
595 | 677 |
596 DISALLOW_COPY_AND_ASSIGN(Scope); | 678 DISALLOW_COPY_AND_ASSIGN(Scope); |
597 }; | 679 }; |
598 | 680 |
| 681 |
| 682 class Event { |
| 683 public: |
| 684 enum Type { |
| 685 SCAVENGER = 0, |
| 686 MARK_COMPACTOR = 1, |
| 687 START = 2 |
| 688 }; |
| 689 |
| 690 // Default constructor leaves the event uninitialized. |
| 691 Event() {} |
| 692 |
| 693 Event(Type type, |
| 694 const char* gc_reason, |
| 695 const char* collector_reason); |
| 696 |
| 697 // Returns a string describing the event type. |
| 698 const char* TypeName(bool short_name) const; |
| 699 |
| 700 // Type of event |
| 701 Type type; |
| 702 |
| 703 const char* gc_reason; |
| 704 const char* collector_reason; |
| 705 |
| 706 // Timestamp set in the constructor. |
| 707 double start_time; |
| 708 |
| 709 // Timestamp set in the destructor. |
| 710 double end_time; |
| 711 |
| 712 // Size of objects in heap set in constructor. |
| 713 intptr_t start_object_size; |
| 714 |
| 715 // Size of objects in heap set in destructor. |
| 716 intptr_t end_object_size; |
| 717 |
| 718 // Size of memory allocated from OS set in constructor. |
| 719 intptr_t start_memory_size; |
| 720 |
| 721 // Size of memory allocated from OS set in destructor. |
| 722 intptr_t end_memory_size; |
| 723 |
| 724 // Total amount of space either wasted or contained in one of free lists |
| 725 // before the current GC. |
| 726 intptr_t start_holes_size; |
| 727 |
| 728 // Total amount of space either wasted or contained in one of free lists |
| 729 // after the current GC. |
| 730 intptr_t end_holes_size; |
| 731 |
| 732 // Number of incremental marking steps since creation of tracer. |
| 733 // (value at start of event) |
| 734 int incremental_marking_steps; |
| 735 |
| 736 // Cumulative duration of incremental marking steps since creation of |
| 737 // tracer. (value at start of event) |
| 738 double incremental_marking_duration; |
| 739 |
| 740 // Longest incremental marking step since start of marking. |
| 741 // (value at start of event) |
| 742 double longest_incremental_marking_step; |
| 743 |
| 744 // Amounts of time spent in different scopes during GC. |
| 745 double scopes[Scope::NUMBER_OF_SCOPES]; |
| 746 }; |
| 747 |
| 748 static const int kRingBufferMaxSize = 10; |
| 749 |
| 750 typedef RingBuffer<Event, kRingBufferMaxSize> EventBuffer; |
| 751 |
599 explicit GCTracer(Heap* heap); | 752 explicit GCTracer(Heap* heap); |
600 | 753 |
601 // Start collecting data. | 754 // Start collecting data. |
602 void start(GarbageCollector collector, | 755 void Start(GarbageCollector collector, |
603 const char* gc_reason, | 756 const char* gc_reason, |
604 const char* collector_reason); | 757 const char* collector_reason); |
605 | 758 |
606 // Stop collecting data and print results. | 759 // Stop collecting data and print results. |
607 void stop(); | 760 void Stop(); |
| 761 |
| 762 // Log an incremental marking step. |
| 763 void AddIncrementalMarkingStep(double duration); |
608 | 764 |
609 private: | 765 private: |
610 // Returns a string matching the collector. | |
611 const char* CollectorString() const; | |
612 | |
613 // Print one detailed trace line in name=value format. | 766 // Print one detailed trace line in name=value format. |
| 767 // TODO(ernstm): Move to Heap. |
614 void PrintNVP() const; | 768 void PrintNVP() const; |
615 | 769 |
616 // Print one trace line. | 770 // Print one trace line. |
| 771 // TODO(ernstm): Move to Heap. |
617 void Print() const; | 772 void Print() const; |
618 | 773 |
619 // Timestamp set in the constructor. | 774 // Pointer to the heap that owns this tracer. |
620 double start_time_; | |
621 | |
622 // Timestamp set in the destructor. | |
623 double end_time_; | |
624 | |
625 // Size of objects in heap set in constructor. | |
626 intptr_t start_object_size_; | |
627 | |
628 // Size of objects in heap set in destructor. | |
629 intptr_t end_object_size_; | |
630 | |
631 // Size of memory allocated from OS set in constructor. | |
632 intptr_t start_memory_size_; | |
633 | |
634 // Size of memory allocated from OS set in destructor. | |
635 intptr_t end_memory_size_; | |
636 | |
637 // Type of collector. | |
638 GarbageCollector collector_; | |
639 | |
640 // Amounts of time spent in different scopes during GC. | |
641 double scopes_[Scope::NUMBER_OF_SCOPES]; | |
642 | |
643 // Total amount of space either wasted or contained in one of free lists | |
644 // before the current GC. | |
645 intptr_t in_free_list_or_wasted_before_gc_; | |
646 | |
647 // Difference between space used in the heap at the beginning of the current | |
648 // collection and the end of the previous collection. | |
649 intptr_t allocated_since_last_gc_; | |
650 | |
651 // Amount of time spent in mutator that is time elapsed between end of the | |
652 // previous collection and the beginning of the current one. | |
653 double spent_in_mutator_; | |
654 | |
655 // Incremental marking steps counters. | |
656 int steps_count_; | |
657 double steps_took_; | |
658 double longest_step_; | |
659 int steps_count_since_last_gc_; | |
660 double steps_took_since_last_gc_; | |
661 | |
662 Heap* heap_; | 775 Heap* heap_; |
663 | 776 |
664 const char* gc_reason_; | 777 // Current tracer event. Populated during Start/Stop cycle. Valid after Stop() |
665 const char* collector_reason_; | 778 // has returned. |
| 779 Event current_; |
| 780 |
| 781 // Previous tracer event. |
| 782 Event previous_; |
| 783 |
| 784 // Previous MARK_COMPACTOR event. |
| 785 Event previous_mark_compactor_event_; |
| 786 |
| 787 // RingBuffers for SCAVENGER events. |
| 788 EventBuffer scavenger_events_; |
| 789 |
| 790 // RingBuffers for MARK_COMPACTOR events. |
| 791 EventBuffer mark_compactor_events_; |
| 792 |
| 793 // Cumulative number of incremental marking steps since creation of tracer. |
| 794 int incremental_marking_steps_; |
| 795 |
| 796 // Cumulative duration of incremental marking steps since creation of tracer. |
| 797 double incremental_marking_duration_; |
| 798 |
| 799 // Longest incremental marking step since start of marking. |
| 800 double longest_incremental_marking_step_; |
666 | 801 |
667 DISALLOW_COPY_AND_ASSIGN(GCTracer); | 802 DISALLOW_COPY_AND_ASSIGN(GCTracer); |
668 }; | 803 }; |
669 | 804 |
670 | 805 |
671 class Heap { | 806 class Heap { |
672 public: | 807 public: |
673 // Configure heap size in MB before setup. Return false if the heap has been | 808 // Configure heap size in MB before setup. Return false if the heap has been |
674 // set up already. | 809 // set up already. |
675 bool ConfigureHeap(int max_semi_space_size, | 810 bool ConfigureHeap(int max_semi_space_size, |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 | 1496 |
1362 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { | 1497 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { |
1363 if (is_crankshafted) { | 1498 if (is_crankshafted) { |
1364 crankshaft_codegen_bytes_generated_ += size; | 1499 crankshaft_codegen_bytes_generated_ += size; |
1365 } else { | 1500 } else { |
1366 full_codegen_bytes_generated_ += size; | 1501 full_codegen_bytes_generated_ += size; |
1367 } | 1502 } |
1368 } | 1503 } |
1369 | 1504 |
1370 // Update GC statistics that are tracked on the Heap. | 1505 // Update GC statistics that are tracked on the Heap. |
1371 void UpdateGCStatistics(double start_time, | 1506 void UpdateCumulativeGCStatistics(double duration, |
1372 double end_time, | 1507 double spent_in_mutator, |
1373 double spent_in_mutator, | 1508 double marking_time); |
1374 double marking_time); | |
1375 | 1509 |
1376 // Returns maximum GC pause. | 1510 // Returns maximum GC pause. |
1377 double get_max_gc_pause() { return max_gc_pause_; } | 1511 double get_max_gc_pause() { return max_gc_pause_; } |
1378 | 1512 |
1379 // Returns maximum size of objects alive after GC. | 1513 // Returns maximum size of objects alive after GC. |
1380 intptr_t get_max_alive_after_gc() { return max_alive_after_gc_; } | 1514 intptr_t get_max_alive_after_gc() { return max_alive_after_gc_; } |
1381 | 1515 |
1382 // Returns minimal interval between two subsequent collections. | 1516 // Returns minimal interval between two subsequent collections. |
1383 double get_min_in_mutator() { return min_in_mutator_; } | 1517 double get_min_in_mutator() { return min_in_mutator_; } |
1384 | 1518 |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2234 | 2368 |
2235 // Total time spent in GC. | 2369 // Total time spent in GC. |
2236 double total_gc_time_ms_; | 2370 double total_gc_time_ms_; |
2237 | 2371 |
2238 // Maximum size of objects alive after GC. | 2372 // Maximum size of objects alive after GC. |
2239 intptr_t max_alive_after_gc_; | 2373 intptr_t max_alive_after_gc_; |
2240 | 2374 |
2241 // Minimal interval between two subsequent collections. | 2375 // Minimal interval between two subsequent collections. |
2242 double min_in_mutator_; | 2376 double min_in_mutator_; |
2243 | 2377 |
2244 // Size of objects alive after last GC. | |
2245 intptr_t alive_after_last_gc_; | |
2246 | |
2247 double last_gc_end_timestamp_; | |
2248 | |
2249 // Cumulative GC time spent in marking | 2378 // Cumulative GC time spent in marking |
2250 double marking_time_; | 2379 double marking_time_; |
2251 | 2380 |
2252 // Cumulative GC time spent in sweeping | 2381 // Cumulative GC time spent in sweeping |
2253 double sweeping_time_; | 2382 double sweeping_time_; |
2254 | 2383 |
2255 MarkCompactCollector mark_compact_collector_; | 2384 MarkCompactCollector mark_compact_collector_; |
2256 | 2385 |
2257 StoreBuffer store_buffer_; | 2386 StoreBuffer store_buffer_; |
2258 | 2387 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2783 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2912 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
2784 | 2913 |
2785 private: | 2914 private: |
2786 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2915 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
2787 }; | 2916 }; |
2788 #endif // DEBUG | 2917 #endif // DEBUG |
2789 | 2918 |
2790 } } // namespace v8::internal | 2919 } } // namespace v8::internal |
2791 | 2920 |
2792 #endif // V8_HEAP_H_ | 2921 #endif // V8_HEAP_H_ |
OLD | NEW |