Chromium Code Reviews| 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 | |
|
Hannes Payer (out of office)
2014/07/23 14:35:15
"."
ernstm
2014/07/23 14:59:27
Done.
| |
| 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. | |
|
Hannes Payer (out of office)
2014/07/23 14:35:15
Unit tests. Move to separate file.
ernstm
2014/07/23 14:59:27
Done.
| |
| 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 typedef RingBuffer<Event, 10> EventBuffer; | |
|
Hannes Payer (out of office)
2014/07/23 14:35:15
Can we make 10 a proper constant.
ernstm
2014/07/23 14:59:27
Done.
| |
| 749 | |
| 599 explicit GCTracer(Heap* heap); | 750 explicit GCTracer(Heap* heap); |
| 600 | 751 |
| 601 // Start collecting data. | 752 // Start collecting data. |
| 602 void start(GarbageCollector collector, | 753 void Start(GarbageCollector collector, |
| 603 const char* gc_reason, | 754 const char* gc_reason, |
| 604 const char* collector_reason); | 755 const char* collector_reason); |
| 605 | 756 |
| 606 // Stop collecting data and print results. | 757 // Stop collecting data and print results. |
| 607 void stop(); | 758 void Stop(); |
| 759 | |
| 760 // Log an incremental marking step. | |
| 761 void AddIncrementalMarkingStep(double duration); | |
| 608 | 762 |
| 609 private: | 763 private: |
| 610 // Returns a string matching the collector. | |
| 611 const char* CollectorString() const; | |
| 612 | |
| 613 // Print one detailed trace line in name=value format. | 764 // Print one detailed trace line in name=value format. |
| 765 // TODO(ernstm): move to Heap. | |
|
Hannes Payer (out of office)
2014/07/23 14:35:15
"Move"
ernstm
2014/07/23 14:59:27
Done.
| |
| 614 void PrintNVP() const; | 766 void PrintNVP() const; |
| 615 | 767 |
| 616 // Print one trace line. | 768 // Print one trace line. |
| 769 // TODO(ernstm): move to Heap. | |
|
Hannes Payer (out of office)
2014/07/23 14:35:15
"Move"
ernstm
2014/07/23 14:59:27
Done.
| |
| 617 void Print() const; | 770 void Print() const; |
| 618 | 771 |
| 619 // Timestamp set in the constructor. | 772 // 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_; | 773 Heap* heap_; |
| 663 | 774 |
| 664 const char* gc_reason_; | 775 // Current tracer event. Populated during Start/Stop cycle. Valid after Stop() |
| 665 const char* collector_reason_; | 776 // has returned. |
| 777 Event current_; | |
| 778 | |
| 779 // Previous tracer event. | |
| 780 Event previous_; | |
| 781 | |
| 782 // Previous MARK_COMPACTOR event. | |
| 783 Event previous_mark_compactor_; | |
|
Hannes Payer (out of office)
2014/07/23 14:35:15
previous_mark_compactor_event_
| |
| 784 | |
| 785 // RingBuffers for SCAVENGER events. | |
| 786 EventBuffer scavenger_events_; | |
| 787 | |
| 788 // RingBuffers for MARK_COMPACTOR events. | |
| 789 EventBuffer mark_compactor_events_; | |
| 790 | |
| 791 // Cumulative number of incremental marking steps since creation of tracer. | |
| 792 int incremental_marking_steps_; | |
| 793 | |
| 794 // Cumulative duration of incremental marking steps since creation of tracer. | |
| 795 double incremental_marking_duration_; | |
| 796 | |
| 797 // Longest incremental marking step since start of marking. | |
| 798 double longest_incremental_marking_step_; | |
| 666 | 799 |
| 667 DISALLOW_COPY_AND_ASSIGN(GCTracer); | 800 DISALLOW_COPY_AND_ASSIGN(GCTracer); |
| 668 }; | 801 }; |
| 669 | 802 |
| 670 | 803 |
| 671 class Heap { | 804 class Heap { |
| 672 public: | 805 public: |
| 673 // Configure heap size in MB before setup. Return false if the heap has been | 806 // Configure heap size in MB before setup. Return false if the heap has been |
| 674 // set up already. | 807 // set up already. |
| 675 bool ConfigureHeap(int max_semi_space_size, | 808 bool ConfigureHeap(int max_semi_space_size, |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 | 1494 |
| 1362 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { | 1495 void IncrementCodeGeneratedBytes(bool is_crankshafted, int size) { |
| 1363 if (is_crankshafted) { | 1496 if (is_crankshafted) { |
| 1364 crankshaft_codegen_bytes_generated_ += size; | 1497 crankshaft_codegen_bytes_generated_ += size; |
| 1365 } else { | 1498 } else { |
| 1366 full_codegen_bytes_generated_ += size; | 1499 full_codegen_bytes_generated_ += size; |
| 1367 } | 1500 } |
| 1368 } | 1501 } |
| 1369 | 1502 |
| 1370 // Update GC statistics that are tracked on the Heap. | 1503 // Update GC statistics that are tracked on the Heap. |
| 1371 void UpdateGCStatistics(double start_time, | 1504 void UpdateCumulativeGCStatistics(double duration, |
| 1372 double end_time, | 1505 double spent_in_mutator, |
| 1373 double spent_in_mutator, | 1506 double marking_time); |
| 1374 double marking_time); | |
| 1375 | 1507 |
| 1376 // Returns maximum GC pause. | 1508 // Returns maximum GC pause. |
| 1377 double get_max_gc_pause() { return max_gc_pause_; } | 1509 double get_max_gc_pause() { return max_gc_pause_; } |
| 1378 | 1510 |
| 1379 // Returns maximum size of objects alive after GC. | 1511 // Returns maximum size of objects alive after GC. |
| 1380 intptr_t get_max_alive_after_gc() { return max_alive_after_gc_; } | 1512 intptr_t get_max_alive_after_gc() { return max_alive_after_gc_; } |
| 1381 | 1513 |
| 1382 // Returns minimal interval between two subsequent collections. | 1514 // Returns minimal interval between two subsequent collections. |
| 1383 double get_min_in_mutator() { return min_in_mutator_; } | 1515 double get_min_in_mutator() { return min_in_mutator_; } |
| 1384 | 1516 |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2234 | 2366 |
| 2235 // Total time spent in GC. | 2367 // Total time spent in GC. |
| 2236 double total_gc_time_ms_; | 2368 double total_gc_time_ms_; |
| 2237 | 2369 |
| 2238 // Maximum size of objects alive after GC. | 2370 // Maximum size of objects alive after GC. |
| 2239 intptr_t max_alive_after_gc_; | 2371 intptr_t max_alive_after_gc_; |
| 2240 | 2372 |
| 2241 // Minimal interval between two subsequent collections. | 2373 // Minimal interval between two subsequent collections. |
| 2242 double min_in_mutator_; | 2374 double min_in_mutator_; |
| 2243 | 2375 |
| 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 | 2376 // Cumulative GC time spent in marking |
| 2250 double marking_time_; | 2377 double marking_time_; |
| 2251 | 2378 |
| 2252 // Cumulative GC time spent in sweeping | 2379 // Cumulative GC time spent in sweeping |
| 2253 double sweeping_time_; | 2380 double sweeping_time_; |
| 2254 | 2381 |
| 2255 MarkCompactCollector mark_compact_collector_; | 2382 MarkCompactCollector mark_compact_collector_; |
| 2256 | 2383 |
| 2257 StoreBuffer store_buffer_; | 2384 StoreBuffer store_buffer_; |
| 2258 | 2385 |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2783 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. | 2910 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
| 2784 | 2911 |
| 2785 private: | 2912 private: |
| 2786 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 2913 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
| 2787 }; | 2914 }; |
| 2788 #endif // DEBUG | 2915 #endif // DEBUG |
| 2789 | 2916 |
| 2790 } } // namespace v8::internal | 2917 } } // namespace v8::internal |
| 2791 | 2918 |
| 2792 #endif // V8_HEAP_H_ | 2919 #endif // V8_HEAP_H_ |
| OLD | NEW |