Chromium Code Reviews| Index: src/heap.h |
| diff --git a/src/heap.h b/src/heap.h |
| index e75c7231ffdd9ea90349584f3a21336e50db9506..8ec65ca4c8e477e326dbf5cce01ac574b72146f2 100644 |
| --- a/src/heap.h |
| +++ b/src/heap.h |
| @@ -547,10 +547,79 @@ enum ArrayStorageAllocationMode { |
| INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE |
| }; |
| +// TODO(ernstm): Move into GCTracer |
| +// A simple ring buffer class with maximum size known at compile time. |
| +// The class only implements the functionality required in GCTracer. |
| +template<typename T, size_t MAX_SIZE> |
| +class RingBuffer { |
| + public: |
| + class const_iterator { |
| + public: |
| + const_iterator() : index_(0), elements_(NULL) {} |
| + |
| + const_iterator(size_t index, const T* elements) : |
| + index_(index), elements_(elements) {} |
| + |
| + bool operator==(const const_iterator& rhs) const { |
| + return elements_ == rhs.elements_ && |
| + index_ == rhs.index_; |
| + } |
| + |
| + bool operator!=(const const_iterator& rhs) const { |
| + return elements_ != rhs.elements_ || |
| + index_ != rhs.index_; |
| + } |
| + |
| + const T* operator->() const { |
| + return elements_ + index_; |
| + } |
| + |
| + const T& operator*() const { |
| + return elements_[index_]; |
| + } |
| + |
| + const_iterator& operator++() { |
| + index_ = (index_ + 1) % (MAX_SIZE + 1); |
| + return *this; |
| + } |
| + |
| + const_iterator& operator--() { |
| + index_ = (index_ + MAX_SIZE) % (MAX_SIZE + 1); |
| + return *this; |
| + } |
| + |
| + private: |
| + size_t index_; |
| + const T* elements_; |
| + }; |
| + |
| + RingBuffer() : begin_(0), end_(0) {} |
| + |
| + bool empty() const { return begin_ == end_; } |
| + size_t size() const { |
| + return (end_ - begin_ + MAX_SIZE + 1) % (MAX_SIZE + 1); |
| + } |
| + const_iterator begin() const { return const_iterator(begin_, elements_); } |
| + const_iterator end() const { return const_iterator(end_, elements_); } |
| + const_iterator back() const { return --end(); } |
| + void push_back(const T& element) { |
| + elements_[end_] = element; |
| + end_ = (end_ + 1) % (MAX_SIZE + 1); |
|
Hannes Payer (out of office)
2014/07/22 15:21:31
Hmm, MAX_SIZE+1 makes the code really complicated.
ernstm
2014/07/22 15:57:25
That is unrelated to anchor elements. The extra el
Hannes Payer (out of office)
2014/07/22 16:29:12
Ahm, yes. I guess we could also use a counter. But
ernstm
2014/07/23 10:32:26
The counter could be used to distinguish empty fro
|
| + if (end_ == begin_) |
| + begin_ = (begin_ + 1) % (MAX_SIZE + 1); |
| + } |
| + |
| + private: |
| + T elements_[MAX_SIZE + 1]; |
| + size_t begin_; |
| + size_t end_; |
|
Hannes Payer (out of office)
2014/07/22 15:21:31
DISALLOW_COPY_AND_ASSIGN
ernstm
2014/07/22 15:57:24
Done.
|
| +}; |
| + |
| // GCTracer collects and prints ONE line after each garbage collector |
| // invocation IFF --trace_gc is used. |
| +// TODO(ernstm): unit tests. move to separate file. |
| class GCTracer BASE_EMBEDDED { |
| public: |
| class Scope BASE_EMBEDDED { |
| @@ -585,7 +654,8 @@ class GCTracer BASE_EMBEDDED { |
| ~Scope() { |
| ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. |
| - tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_; |
| + tracer_->pending_.scopes[scope_] += |
| + base::OS::TimeCurrentMillis() - start_time_; |
| } |
| private: |
| @@ -596,73 +666,123 @@ class GCTracer BASE_EMBEDDED { |
| DISALLOW_COPY_AND_ASSIGN(Scope); |
| }; |
| + |
| + class Event { |
| + public: |
| + enum Type { |
| + SCAVENGER = 0, |
| + MARK_COMPACTOR = 1, |
| + ANCHOR = 2, |
| + INVALID = 3 |
|
Hannes Payer (out of office)
2014/07/22 15:21:30
what is the purpose of invalid?
ernstm
2014/07/22 15:57:25
Not really required. See commend on default constr
|
| + }; |
| + |
| + Event(); |
| + |
| + Event(Type type, |
| + const char* gc_reason, |
| + const char* collector_reason); |
| + |
| + // Returns a string describing the event type. |
| + const char* TypeName(bool short_name) const; |
| + |
| + // Type of event |
| + Type type; |
| + |
| + const char* gc_reason; |
| + const char* collector_reason; |
| + |
| + // Timestamp set in the constructor. |
| + double start_time; |
| + |
| + // Timestamp set in the destructor. |
| + double end_time; |
| + |
| + // Size of objects in heap set in constructor. |
| + intptr_t start_object_size; |
| + |
| + // Size of objects in heap set in destructor. |
| + intptr_t end_object_size; |
| + |
| + // Size of memory allocated from OS set in constructor. |
| + intptr_t start_memory_size; |
| + |
| + // Size of memory allocated from OS set in destructor. |
| + intptr_t end_memory_size; |
| + |
| + // Total amount of space either wasted or contained in one of free lists |
| + // before the current GC. |
| + intptr_t start_holes_size; |
| + |
| + // Total amount of space either wasted or contained in one of free lists |
| + // after the current GC. |
| + intptr_t end_holes_size; |
| + |
| + // Number of incremental marking steps since creation of tracer. |
| + // (value at start of event) |
| + int incremental_marking_steps; |
| + |
| + // Cumulative duration of incremental marking steps since creation of |
| + // tracer. (value at start of event) |
| + double incremental_marking_duration; |
| + |
| + // Longest incremental marking step since start of marking. |
| + // (value at start of event) |
| + double longest_incremental_marking_step; |
| + |
| + // Amounts of time spent in different scopes during GC. |
| + double scopes[Scope::NUMBER_OF_SCOPES]; |
| + }; |
| + |
| + typedef RingBuffer<Event, 10> EventBuffer; |
| + |
| explicit GCTracer(Heap* heap); |
| // Start collecting data. |
| - void start(GarbageCollector collector, |
| + void Start(GarbageCollector collector, |
| const char* gc_reason, |
| const char* collector_reason); |
| // Stop collecting data and print results. |
| - void stop(); |
| + void Stop(); |
| - private: |
| - // Returns a string matching the collector. |
| - const char* CollectorString() const; |
| + // The event with the most recent end_time (selected from all event buffer) |
| + EventBuffer::const_iterator Current() const; |
| + |
| + // The event before the current event (selected from all event buffers). |
| + EventBuffer::const_iterator Previous() const; |
| + |
| + // Log an incremental marking step. |
| + void AddIncrementalMarkingStep(double duration); |
| + private: |
| // Print one detailed trace line in name=value format. |
| + // TODO(ernstm): move to Heap. |
| void PrintNVP() const; |
| // Print one trace line. |
| + // TODO(ernstm): move to Heap. |
| void Print() const; |
| - // Timestamp set in the constructor. |
| - double start_time_; |
| - |
| - // Timestamp set in the destructor. |
| - double end_time_; |
| - |
| - // Size of objects in heap set in constructor. |
| - intptr_t start_object_size_; |
| - |
| - // Size of objects in heap set in destructor. |
| - intptr_t end_object_size_; |
| - |
| - // Size of memory allocated from OS set in constructor. |
| - intptr_t start_memory_size_; |
| - |
| - // Size of memory allocated from OS set in destructor. |
| - intptr_t end_memory_size_; |
| - |
| - // Type of collector. |
| - GarbageCollector collector_; |
| - |
| - // Amounts of time spent in different scopes during GC. |
| - double scopes_[Scope::NUMBER_OF_SCOPES]; |
| + // Pointer to the heap that owns this tracer. |
| + Heap* heap_; |
| - // Total amount of space either wasted or contained in one of free lists |
| - // before the current GC. |
| - intptr_t in_free_list_or_wasted_before_gc_; |
| + // Pending tracer event that is filled during one Start/Stop cycle. |
| + Event pending_; |
| - // Difference between space used in the heap at the beginning of the current |
| - // collection and the end of the previous collection. |
| - intptr_t allocated_since_last_gc_; |
| + // RingBuffers for SCAVENGER events. |
| + EventBuffer scavenger_events_; |
| - // Amount of time spent in mutator that is time elapsed between end of the |
| - // previous collection and the beginning of the current one. |
| - double spent_in_mutator_; |
| + // RingBuffers for MARK_COMPACTOR events. |
| + EventBuffer mark_compactor_events_; |
| - // Incremental marking steps counters. |
| - int steps_count_; |
| - double steps_took_; |
| - double longest_step_; |
| - int steps_count_since_last_gc_; |
| - double steps_took_since_last_gc_; |
| + // Cumulative number of incremental marking steps since creation of tracer. |
| + int incremental_marking_steps_; |
| - Heap* heap_; |
| + // Cumulative duration of incremental marking steps since creation of tracer. |
| + double incremental_marking_duration_; |
| - const char* gc_reason_; |
| - const char* collector_reason_; |
| + // Longest incremental marking step since start of marking. |
| + double longest_incremental_marking_step_; |
| DISALLOW_COPY_AND_ASSIGN(GCTracer); |
| }; |
| @@ -1368,10 +1488,9 @@ class Heap { |
| } |
| // Update GC statistics that are tracked on the Heap. |
| - void UpdateGCStatistics(double start_time, |
| - double end_time, |
| - double spent_in_mutator, |
| - double marking_time); |
| + void UpdateCumulativeGCStatistics(double duration, |
| + double spent_in_mutator, |
| + double marking_time); |
| // Returns maximum GC pause. |
| double get_max_gc_pause() { return max_gc_pause_; } |
| @@ -2241,11 +2360,6 @@ class Heap { |
| // Minimal interval between two subsequent collections. |
| double min_in_mutator_; |
| - // Size of objects alive after last GC. |
| - intptr_t alive_after_last_gc_; |
| - |
| - double last_gc_end_timestamp_; |
| - |
| // Cumulative GC time spent in marking |
| double marking_time_; |