Revert "Track history of events in GCTracer."

This reverts commit 22567 for breaking win64 compile.

BUG=
TBR=ernstm@chromium.org

Review URL: https://codereview.chromium.org/414743002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22572 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5169bcb9
...@@ -53,17 +53,18 @@ Heap::Heap() ...@@ -53,17 +53,18 @@ Heap::Heap()
amount_of_external_allocated_memory_at_last_global_gc_(0), amount_of_external_allocated_memory_at_last_global_gc_(0),
isolate_(NULL), isolate_(NULL),
code_range_size_(0), code_range_size_(0),
// semispace_size_ should be a power of 2 and old_generation_size_ should be // semispace_size_ should be a power of 2 and old_generation_size_ should
// a multiple of Page::kPageSize. // be
// a multiple of Page::kPageSize.
reserved_semispace_size_(8 * (kPointerSize / 4) * MB), reserved_semispace_size_(8 * (kPointerSize / 4) * MB),
max_semi_space_size_(8 * (kPointerSize / 4) * MB), max_semi_space_size_(8 * (kPointerSize / 4) * MB),
initial_semispace_size_(Page::kPageSize), initial_semispace_size_(Page::kPageSize),
max_old_generation_size_(700ul * (kPointerSize / 4) * MB), max_old_generation_size_(700ul * (kPointerSize / 4) * MB),
max_executable_size_(256ul * (kPointerSize / 4) * MB), max_executable_size_(256ul * (kPointerSize / 4) * MB),
// Variables set based on semispace_size_ and old_generation_size_ in // Variables set based on semispace_size_ and old_generation_size_ in
// ConfigureHeap. // ConfigureHeap.
// Will be 4 * reserved_semispace_size_ to ensure that young // Will be 4 * reserved_semispace_size_ to ensure that young
// generation can be aligned to its size. // generation can be aligned to its size.
maximum_committed_(0), maximum_committed_(0),
survived_since_last_expansion_(0), survived_since_last_expansion_(0),
sweep_generation_(0), sweep_generation_(0),
...@@ -113,6 +114,8 @@ Heap::Heap() ...@@ -113,6 +114,8 @@ Heap::Heap()
total_gc_time_ms_(0.0), total_gc_time_ms_(0.0),
max_alive_after_gc_(0), max_alive_after_gc_(0),
min_in_mutator_(kMaxInt), min_in_mutator_(kMaxInt),
alive_after_last_gc_(0),
last_gc_end_timestamp_(base::OS::TimeCurrentMillis()),
marking_time_(0.0), marking_time_(0.0),
sweeping_time_(0.0), sweeping_time_(0.0),
mark_compact_collector_(this), mark_compact_collector_(this),
...@@ -838,7 +841,8 @@ bool Heap::CollectGarbage(GarbageCollector collector, ...@@ -838,7 +841,8 @@ bool Heap::CollectGarbage(GarbageCollector collector,
bool next_gc_likely_to_collect_more = false; bool next_gc_likely_to_collect_more = false;
{ tracer()->Start(collector, gc_reason, collector_reason); {
tracer()->start(collector, gc_reason, collector_reason);
ASSERT(AllowHeapAllocation::IsAllowed()); ASSERT(AllowHeapAllocation::IsAllowed());
DisallowHeapAllocation no_allocation_during_gc; DisallowHeapAllocation no_allocation_during_gc;
GarbageCollectionPrologue(); GarbageCollectionPrologue();
...@@ -852,7 +856,7 @@ bool Heap::CollectGarbage(GarbageCollector collector, ...@@ -852,7 +856,7 @@ bool Heap::CollectGarbage(GarbageCollector collector,
} }
GarbageCollectionEpilogue(); GarbageCollectionEpilogue();
tracer()->Stop(); tracer()->stop();
} }
// Start incremental marking for the next cycle. The heap snapshot // Start incremental marking for the next cycle. The heap snapshot
...@@ -5965,13 +5969,16 @@ static intptr_t CountTotalHolesSize(Heap* heap) { ...@@ -5965,13 +5969,16 @@ static intptr_t CountTotalHolesSize(Heap* heap) {
} }
void Heap::UpdateCumulativeGCStatistics(double duration, void Heap::UpdateGCStatistics(double start_time, double end_time,
double spent_in_mutator, double spent_in_mutator, double marking_time) {
double marking_time) { double duration = end_time - start_time;
alive_after_last_gc_ = SizeOfObjects();
last_gc_end_timestamp_ = end_time;
if (FLAG_print_cumulative_gc_stat) { if (FLAG_print_cumulative_gc_stat) {
total_gc_time_ms_ += duration; total_gc_time_ms_ += duration;
max_gc_pause_ = Max(max_gc_pause_, duration); max_gc_pause_ = Max(max_gc_pause_, duration);
max_alive_after_gc_ = Max(max_alive_after_gc_, SizeOfObjects()); max_alive_after_gc_ = Max(max_alive_after_gc_, alive_after_last_gc_);
min_in_mutator_ = Min(min_in_mutator_, spent_in_mutator); min_in_mutator_ = Min(min_in_mutator_, spent_in_mutator);
} else if (FLAG_trace_gc_verbose) { } else if (FLAG_trace_gc_verbose) {
total_gc_time_ms_ += duration; total_gc_time_ms_ += duration;
...@@ -5981,121 +5988,74 @@ void Heap::UpdateCumulativeGCStatistics(double duration, ...@@ -5981,121 +5988,74 @@ void Heap::UpdateCumulativeGCStatistics(double duration,
} }
GCTracer::Event::Event(Type type, GCTracer::GCTracer(Heap* heap)
const char* gc_reason, : start_time_(0.0),
const char* collector_reason) end_time_(0.0),
: type(type), start_object_size_(0),
gc_reason(gc_reason), end_object_size_(0),
collector_reason(collector_reason), start_memory_size_(0),
start_time(0.0), end_memory_size_(0),
end_time(0.0), in_free_list_or_wasted_before_gc_(0),
start_object_size(0), allocated_since_last_gc_(0),
end_object_size(0), spent_in_mutator_(0),
start_memory_size(0), steps_count_(0),
end_memory_size(0), steps_took_(0.0),
start_holes_size(0), longest_step_(0.0),
end_holes_size(0), steps_count_since_last_gc_(0),
incremental_marking_steps(0), steps_took_since_last_gc_(0.0),
incremental_marking_duration(0.0) { heap_(heap),
gc_reason_(NULL),
collector_reason_(NULL) {
for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) { for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) {
scopes[i] = 0; scopes_[i] = 0;
}
}
const char* GCTracer::Event::TypeName(bool short_name) const {
switch (type) {
case SCAVENGER:
if (short_name) {
return "s";
} else {
return "Scavenge";
}
case MARK_COMPACTOR:
if (short_name) {
return "ms";
} else {
return "Mark-sweep";
}
case START:
if (short_name) {
return "st";
} else {
return "Start";
} }
}
return "Unknown Event Type";
} }
GCTracer::GCTracer(Heap* heap) void GCTracer::start(GarbageCollector collector, const char* gc_reason,
: heap_(heap),
incremental_marking_steps_(0),
incremental_marking_duration_(0.0),
longest_incremental_marking_step_(0.0) {
current_ = Event(Event::START, NULL, NULL);
current_.end_time = base::OS::TimeCurrentMillis();
previous_ = previous_mark_compactor_event_ = current_;
}
void GCTracer::Start(GarbageCollector collector,
const char* gc_reason,
const char* collector_reason) { const char* collector_reason) {
if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return;
previous_ = current_; collector_ = collector;
if (current_.type == Event::MARK_COMPACTOR) gc_reason_ = gc_reason;
previous_mark_compactor_event_ = current_; collector_reason_ = collector_reason;
if (collector == SCAVENGER) {
current_ = Event(Event::SCAVENGER, gc_reason, collector_reason);
} else {
current_ = Event(Event::MARK_COMPACTOR, gc_reason, collector_reason);
}
current_.start_time = base::OS::TimeCurrentMillis();
current_.start_object_size = heap_->SizeOfObjects();
current_.start_memory_size = heap_->isolate()->memory_allocator()->Size();
current_.start_holes_size = CountTotalHolesSize(heap_);
current_.incremental_marking_steps = incremental_marking_steps_; start_time_ = base::OS::TimeCurrentMillis();
current_.incremental_marking_duration = incremental_marking_duration_; start_object_size_ = heap_->SizeOfObjects();
current_.longest_incremental_marking_step = longest_incremental_marking_step_; start_memory_size_ = heap_->isolate()->memory_allocator()->Size();
for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) { for (int i = 0; i < Scope::NUMBER_OF_SCOPES; i++) {
current_.scopes[i] = 0; scopes_[i] = 0;
} }
}
in_free_list_or_wasted_before_gc_ = CountTotalHolesSize(heap_);
void GCTracer::Stop() { allocated_since_last_gc_ =
if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; heap_->SizeOfObjects() - heap_->alive_after_last_gc_;
current_.end_time = base::OS::TimeCurrentMillis(); spent_in_mutator_ = Max(start_time_ - heap_->last_gc_end_timestamp_, 0.0);
current_.end_object_size = heap_->SizeOfObjects();
current_.end_memory_size = heap_->isolate()->memory_allocator()->Size(); steps_count_ = heap_->incremental_marking()->steps_count();
current_.end_holes_size = CountTotalHolesSize(heap_); steps_took_ = heap_->incremental_marking()->steps_took();
longest_step_ = heap_->incremental_marking()->longest_step();
steps_count_since_last_gc_ =
heap_->incremental_marking()->steps_count_since_last_gc();
steps_took_since_last_gc_ =
heap_->incremental_marking()->steps_took_since_last_gc();
}
if (current_.type == Event::SCAVENGER) {
scavenger_events_.push_front(current_);
} else {
mark_compactor_events_.push_front(current_);
}
if (current_.type == Event::MARK_COMPACTOR) void GCTracer::stop() {
longest_incremental_marking_step_ = 0.0; if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return;
double duration = current_.end_time - current_.start_time; end_time_ = base::OS::TimeCurrentMillis();
double spent_in_mutator = end_object_size_ = heap_->SizeOfObjects();
Max(current_.start_time - previous_.end_time, 0.0); end_memory_size_ = heap_->isolate()->memory_allocator()->Size();
heap_->UpdateCumulativeGCStatistics(duration, heap_->UpdateGCStatistics(start_time_, end_time_, spent_in_mutator_,
spent_in_mutator, scopes_[Scope::MC_MARK]);
current_.scopes[Scope::MC_MARK]);
if (current_.type == Event::SCAVENGER && FLAG_trace_gc_ignore_scavenger) if (collector_ == SCAVENGER && FLAG_trace_gc_ignore_scavenger) return;
return;
if (FLAG_trace_gc) { if (FLAG_trace_gc) {
if (FLAG_trace_gc_nvp) if (FLAG_trace_gc_nvp)
...@@ -6108,57 +6068,37 @@ void GCTracer::Stop() { ...@@ -6108,57 +6068,37 @@ void GCTracer::Stop() {
} }
void GCTracer::AddIncrementalMarkingStep(double duration) {
incremental_marking_steps_++;
incremental_marking_duration_ += duration;
longest_incremental_marking_step_ =
Max(longest_incremental_marking_step_, duration);
}
void GCTracer::Print() const { void GCTracer::Print() const {
PrintPID("%8.0f ms: ", heap_->isolate()->time_millis_since_init()); PrintPID("%8.0f ms: ", heap_->isolate()->time_millis_since_init());
PrintF("%s %.1f (%.1f) -> %.1f (%.1f) MB, ", PrintF("%s %.1f (%.1f) -> %.1f (%.1f) MB, ", CollectorString(),
current_.TypeName(false), static_cast<double>(start_object_size_) / MB,
static_cast<double>(current_.start_object_size) / MB, static_cast<double>(start_memory_size_) / MB,
static_cast<double>(current_.start_memory_size) / MB, static_cast<double>(end_object_size_) / MB,
static_cast<double>(current_.end_object_size) / MB, static_cast<double>(end_memory_size_) / MB);
static_cast<double>(current_.end_memory_size) / MB);
int external_time = static_cast<int>(current_.scopes[Scope::EXTERNAL]); int external_time = static_cast<int>(scopes_[Scope::EXTERNAL]);
if (external_time > 0) PrintF("%d / ", external_time); if (external_time > 0) PrintF("%d / ", external_time);
double duration = current_.end_time - current_.start_time; PrintF("%.1f ms", end_time_ - start_time_);
PrintF("%.1f ms", duration); if (steps_count_ > 0) {
if (current_.type == Event::SCAVENGER) { if (collector_ == SCAVENGER) {
int steps = current_.incremental_marking_steps -
previous_.incremental_marking_steps;
if (steps > 0) {
PrintF(" (+ %.1f ms in %d steps since last GC)", PrintF(" (+ %.1f ms in %d steps since last GC)",
current_.incremental_marking_duration - steps_took_since_last_gc_, steps_count_since_last_gc_);
previous_.incremental_marking_duration,
steps);
}
} else { } else {
int steps = current_.incremental_marking_steps - PrintF(
previous_mark_compactor_event_.incremental_marking_steps; " (+ %.1f ms in %d steps since start of marking, "
if (steps > 0) {
PrintF(" (+ %.1f ms in %d steps since start of marking, "
"biggest step %.1f ms)", "biggest step %.1f ms)",
current_.incremental_marking_duration - steps_took_, steps_count_, longest_step_);
previous_mark_compactor_event_.incremental_marking_duration,
steps,
current_.longest_incremental_marking_step);
} }
} }
if (current_.gc_reason != NULL) { if (gc_reason_ != NULL) {
PrintF(" [%s]", current_.gc_reason); PrintF(" [%s]", gc_reason_);
} }
if (current_.collector_reason != NULL) { if (collector_reason_ != NULL) {
PrintF(" [%s]", current_.collector_reason); PrintF(" [%s]", collector_reason_);
} }
PrintF(".\n"); PrintF(".\n");
...@@ -6168,47 +6108,49 @@ void GCTracer::Print() const { ...@@ -6168,47 +6108,49 @@ void GCTracer::Print() const {
void GCTracer::PrintNVP() const { void GCTracer::PrintNVP() const {
PrintPID("%8.0f ms: ", heap_->isolate()->time_millis_since_init()); PrintPID("%8.0f ms: ", heap_->isolate()->time_millis_since_init());
double duration = current_.end_time - current_.start_time; PrintF("pause=%.1f ", end_time_ - start_time_);
double spent_in_mutator = current_.start_time - previous_.end_time; PrintF("mutator=%.1f ", spent_in_mutator_);
PrintF("gc=");
PrintF("pause=%.1f ", duration); switch (collector_) {
PrintF("mutator=%.1f ", spent_in_mutator); case SCAVENGER:
PrintF("gc=%s ", current_.TypeName(true)); PrintF("s");
break;
PrintF("external=%.1f ", current_.scopes[Scope::EXTERNAL]); case MARK_COMPACTOR:
PrintF("mark=%.1f ", current_.scopes[Scope::MC_MARK]); PrintF("ms");
PrintF("sweep=%.2f ", current_.scopes[Scope::MC_SWEEP]); break;
PrintF("sweepns=%.2f ", current_.scopes[Scope::MC_SWEEP_NEWSPACE]); default:
PrintF("sweepos=%.2f ", current_.scopes[Scope::MC_SWEEP_OLDSPACE]); UNREACHABLE();
PrintF("sweepcode=%.2f ", current_.scopes[Scope::MC_SWEEP_CODE]); }
PrintF("sweepcell=%.2f ", current_.scopes[Scope::MC_SWEEP_CELL]); PrintF(" ");
PrintF("sweepmap=%.2f ", current_.scopes[Scope::MC_SWEEP_MAP]);
PrintF("evacuate=%.1f ", current_.scopes[Scope::MC_EVACUATE_PAGES]); PrintF("external=%.1f ", scopes_[Scope::EXTERNAL]);
PrintF("new_new=%.1f ", PrintF("mark=%.1f ", scopes_[Scope::MC_MARK]);
current_.scopes[Scope::MC_UPDATE_NEW_TO_NEW_POINTERS]); PrintF("sweep=%.2f ", scopes_[Scope::MC_SWEEP]);
PrintF("root_new=%.1f ", PrintF("sweepns=%.2f ", scopes_[Scope::MC_SWEEP_NEWSPACE]);
current_.scopes[Scope::MC_UPDATE_ROOT_TO_NEW_POINTERS]); PrintF("sweepos=%.2f ", scopes_[Scope::MC_SWEEP_OLDSPACE]);
PrintF("old_new=%.1f ", PrintF("sweepcode=%.2f ", scopes_[Scope::MC_SWEEP_CODE]);
current_.scopes[Scope::MC_UPDATE_OLD_TO_NEW_POINTERS]); PrintF("sweepcell=%.2f ", scopes_[Scope::MC_SWEEP_CELL]);
PrintF("sweepmap=%.2f ", scopes_[Scope::MC_SWEEP_MAP]);
PrintF("evacuate=%.1f ", scopes_[Scope::MC_EVACUATE_PAGES]);
PrintF("new_new=%.1f ", scopes_[Scope::MC_UPDATE_NEW_TO_NEW_POINTERS]);
PrintF("root_new=%.1f ", scopes_[Scope::MC_UPDATE_ROOT_TO_NEW_POINTERS]);
PrintF("old_new=%.1f ", scopes_[Scope::MC_UPDATE_OLD_TO_NEW_POINTERS]);
PrintF("compaction_ptrs=%.1f ", PrintF("compaction_ptrs=%.1f ",
current_.scopes[Scope::MC_UPDATE_POINTERS_TO_EVACUATED]); scopes_[Scope::MC_UPDATE_POINTERS_TO_EVACUATED]);
PrintF("intracompaction_ptrs=%.1f ", PrintF("intracompaction_ptrs=%.1f ",
current_.scopes[Scope::MC_UPDATE_POINTERS_BETWEEN_EVACUATED]); scopes_[Scope::MC_UPDATE_POINTERS_BETWEEN_EVACUATED]);
PrintF("misc_compaction=%.1f ", PrintF("misc_compaction=%.1f ", scopes_[Scope::MC_UPDATE_MISC_POINTERS]);
current_.scopes[Scope::MC_UPDATE_MISC_POINTERS]);
PrintF("weakcollection_process=%.1f ", PrintF("weakcollection_process=%.1f ",
current_.scopes[Scope::MC_WEAKCOLLECTION_PROCESS]); scopes_[Scope::MC_WEAKCOLLECTION_PROCESS]);
PrintF("weakcollection_clear=%.1f ", PrintF("weakcollection_clear=%.1f ", scopes_[Scope::MC_WEAKCOLLECTION_CLEAR]);
current_.scopes[Scope::MC_WEAKCOLLECTION_CLEAR]);
PrintF("total_size_before=%" V8_PTR_PREFIX "d ", start_object_size_);
PrintF("total_size_before=%" V8_PTR_PREFIX "d ", current_.start_object_size); PrintF("total_size_after=%" V8_PTR_PREFIX "d ", end_object_size_);
PrintF("total_size_after=%" V8_PTR_PREFIX "d ", current_.end_object_size); PrintF("holes_size_before=%" V8_PTR_PREFIX "d ",
PrintF("holes_size_before=%" V8_PTR_PREFIX "d ", current_.start_holes_size); in_free_list_or_wasted_before_gc_);
PrintF("holes_size_after=%" V8_PTR_PREFIX "d ", current_.end_holes_size); PrintF("holes_size_after=%" V8_PTR_PREFIX "d ", CountTotalHolesSize(heap_));
intptr_t allocated_since_last_gc = PrintF("allocated=%" V8_PTR_PREFIX "d ", allocated_since_last_gc_);
current_.start_object_size - previous_.end_object_size;
PrintF("allocated=%" V8_PTR_PREFIX "d ", allocated_since_last_gc);
PrintF("promoted=%" V8_PTR_PREFIX "d ", heap_->promoted_objects_size_); PrintF("promoted=%" V8_PTR_PREFIX "d ", heap_->promoted_objects_size_);
PrintF("semi_space_copied=%" V8_PTR_PREFIX "d ", PrintF("semi_space_copied=%" V8_PTR_PREFIX "d ",
heap_->semi_space_copied_object_size_); heap_->semi_space_copied_object_size_);
...@@ -6218,23 +6160,30 @@ void GCTracer::PrintNVP() const { ...@@ -6218,23 +6160,30 @@ void GCTracer::PrintNVP() const {
PrintF("promotion_rate=%.1f%% ", heap_->promotion_rate_); PrintF("promotion_rate=%.1f%% ", heap_->promotion_rate_);
PrintF("semi_space_copy_rate=%.1f%% ", heap_->semi_space_copied_rate_); PrintF("semi_space_copy_rate=%.1f%% ", heap_->semi_space_copied_rate_);
if (current_.type == Event::SCAVENGER) { if (collector_ == SCAVENGER) {
PrintF("stepscount=%d ", current_.incremental_marking_steps - PrintF("stepscount=%d ", steps_count_since_last_gc_);
previous_.incremental_marking_steps); PrintF("stepstook=%.1f ", steps_took_since_last_gc_);
PrintF("stepstook=%.1f ", current_.incremental_marking_duration -
previous_.incremental_marking_duration);
} else { } else {
PrintF("stepscount=%d ", current_.incremental_marking_steps - PrintF("stepscount=%d ", steps_count_);
previous_mark_compactor_event_.incremental_marking_steps); PrintF("stepstook=%.1f ", steps_took_);
PrintF("stepstook=%.1f ", current_.incremental_marking_duration - PrintF("longeststep=%.1f ", longest_step_);
previous_mark_compactor_event_.incremental_marking_duration);
PrintF("longeststep=%.1f ", current_.longest_incremental_marking_step);
} }
PrintF("\n"); PrintF("\n");
} }
const char* GCTracer::CollectorString() const {
switch (collector_) {
case SCAVENGER:
return "Scavenge";
case MARK_COMPACTOR:
return "Mark-sweep";
}
return "Unknown GC";
}
int KeyedLookupCache::Hash(Handle<Map> map, Handle<Name> name) { int KeyedLookupCache::Hash(Handle<Map> map, Handle<Name> name) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
// Uses only lower 32 bits if pointers are larger. // Uses only lower 32 bits if pointers are larger.
......
...@@ -547,91 +547,10 @@ enum ArrayStorageAllocationMode { ...@@ -547,91 +547,10 @@ enum ArrayStorageAllocationMode {
INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE 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_;
}
operator const T*() const {
return elements_ + 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);
if (end_ == begin_)
begin_ = (begin_ + 1) % (MAX_SIZE + 1);
}
void push_front(const T& element) {
begin_ = (begin_ + MAX_SIZE) % (MAX_SIZE + 1);
if (begin_ == end_)
end_ = (end_ + MAX_SIZE) % (MAX_SIZE + 1);
elements_[begin_] = element;
}
private:
T elements_[MAX_SIZE + 1];
size_t begin_;
size_t end_;
DISALLOW_COPY_AND_ASSIGN(RingBuffer);
};
// GCTracer collects and prints ONE line after each garbage collector // GCTracer collects and prints ONE line after each garbage collector
// invocation IFF --trace_gc is used. // invocation IFF --trace_gc is used.
// TODO(ernstm): Unit tests. Move to separate file.
class GCTracer BASE_EMBEDDED { class GCTracer BASE_EMBEDDED {
public: public:
class Scope BASE_EMBEDDED { class Scope BASE_EMBEDDED {
...@@ -666,8 +585,7 @@ class GCTracer BASE_EMBEDDED { ...@@ -666,8 +585,7 @@ class GCTracer BASE_EMBEDDED {
~Scope() { ~Scope() {
ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned. ASSERT(scope_ < NUMBER_OF_SCOPES); // scope_ is unsigned.
tracer_->current_.scopes[scope_] += tracer_->scopes_[scope_] += base::OS::TimeCurrentMillis() - start_time_;
base::OS::TimeCurrentMillis() - start_time_;
} }
private: private:
...@@ -678,126 +596,72 @@ class GCTracer BASE_EMBEDDED { ...@@ -678,126 +596,72 @@ class GCTracer BASE_EMBEDDED {
DISALLOW_COPY_AND_ASSIGN(Scope); DISALLOW_COPY_AND_ASSIGN(Scope);
}; };
explicit GCTracer(Heap* heap);
class Event { // Start collecting data.
public: void start(GarbageCollector collector, const char* gc_reason,
enum Type {
SCAVENGER = 0,
MARK_COMPACTOR = 1,
START = 2
};
// Default constructor leaves the event uninitialized.
Event() {}
Event(Type type,
const char* gc_reason,
const char* collector_reason); const char* collector_reason);
// Returns a string describing the event type. // Stop collecting data and print results.
const char* TypeName(bool short_name) const; void stop();
private:
// Returns a string matching the collector.
const char* CollectorString() const;
// Type of event // Print one detailed trace line in name=value format.
Type type; void PrintNVP() const;
const char* gc_reason; // Print one trace line.
const char* collector_reason; void Print() const;
// Timestamp set in the constructor. // Timestamp set in the constructor.
double start_time; double start_time_;
// Timestamp set in the destructor. // Timestamp set in the destructor.
double end_time; double end_time_;
// Size of objects in heap set in constructor. // Size of objects in heap set in constructor.
intptr_t start_object_size; intptr_t start_object_size_;
// Size of objects in heap set in destructor. // Size of objects in heap set in destructor.
intptr_t end_object_size; intptr_t end_object_size_;
// Size of memory allocated from OS set in constructor. // Size of memory allocated from OS set in constructor.
intptr_t start_memory_size; intptr_t start_memory_size_;
// Size of memory allocated from OS set in destructor. // Size of memory allocated from OS set in destructor.
intptr_t end_memory_size; 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. // Type of collector.
// (value at start of event) GarbageCollector collector_;
double longest_incremental_marking_step;
// Amounts of time spent in different scopes during GC. // Amounts of time spent in different scopes during GC.
double scopes[Scope::NUMBER_OF_SCOPES]; double scopes_[Scope::NUMBER_OF_SCOPES];
};
static const int kRingBufferMaxSize = 10;
typedef RingBuffer<Event, kRingBufferMaxSize> EventBuffer; // Total amount of space either wasted or contained in one of free lists
// before the current GC.
explicit GCTracer(Heap* heap); intptr_t in_free_list_or_wasted_before_gc_;
// Start collecting data.
void Start(GarbageCollector collector,
const char* gc_reason,
const char* collector_reason);
// Stop collecting data and print results.
void Stop();
// Log an incremental marking step. // Difference between space used in the heap at the beginning of the current
void AddIncrementalMarkingStep(double duration); // collection and the end of the previous collection.
intptr_t allocated_since_last_gc_;
private: // Amount of time spent in mutator that is time elapsed between end of the
// Print one detailed trace line in name=value format. // previous collection and the beginning of the current one.
// TODO(ernstm): Move to Heap. double spent_in_mutator_;
void PrintNVP() const;
// Print one trace line. // Incremental marking steps counters.
// TODO(ernstm): Move to Heap. int steps_count_;
void Print() const; double steps_took_;
double longest_step_;
int steps_count_since_last_gc_;
double steps_took_since_last_gc_;
// Pointer to the heap that owns this tracer.
Heap* heap_; Heap* heap_;
// Current tracer event. Populated during Start/Stop cycle. Valid after Stop() const char* gc_reason_;
// has returned. const char* collector_reason_;
Event current_;
// Previous tracer event.
Event previous_;
// Previous MARK_COMPACTOR event.
Event previous_mark_compactor_event_;
// RingBuffers for SCAVENGER events.
EventBuffer scavenger_events_;
// RingBuffers for MARK_COMPACTOR events.
EventBuffer mark_compactor_events_;
// Cumulative number of incremental marking steps since creation of tracer.
int incremental_marking_steps_;
// Cumulative duration of incremental marking steps since creation of tracer.
double incremental_marking_duration_;
// Longest incremental marking step since start of marking.
double longest_incremental_marking_step_;
DISALLOW_COPY_AND_ASSIGN(GCTracer); DISALLOW_COPY_AND_ASSIGN(GCTracer);
}; };
...@@ -1503,9 +1367,8 @@ class Heap { ...@@ -1503,9 +1367,8 @@ class Heap {
} }
// Update GC statistics that are tracked on the Heap. // Update GC statistics that are tracked on the Heap.
void UpdateCumulativeGCStatistics(double duration, void UpdateGCStatistics(double start_time, double end_time,
double spent_in_mutator, double spent_in_mutator, double marking_time);
double marking_time);
// Returns maximum GC pause. // Returns maximum GC pause.
double get_max_gc_pause() { return max_gc_pause_; } double get_max_gc_pause() { return max_gc_pause_; }
...@@ -2375,6 +2238,11 @@ class Heap { ...@@ -2375,6 +2238,11 @@ class Heap {
// Minimal interval between two subsequent collections. // Minimal interval between two subsequent collections.
double min_in_mutator_; 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 // Cumulative GC time spent in marking
double marking_time_; double marking_time_;
......
...@@ -22,14 +22,17 @@ IncrementalMarking::IncrementalMarking(Heap* heap) ...@@ -22,14 +22,17 @@ IncrementalMarking::IncrementalMarking(Heap* heap)
marking_deque_memory_(NULL), marking_deque_memory_(NULL),
marking_deque_memory_committed_(false), marking_deque_memory_committed_(false),
steps_count_(0), steps_count_(0),
steps_took_(0),
longest_step_(0.0),
old_generation_space_available_at_start_of_incremental_(0), old_generation_space_available_at_start_of_incremental_(0),
old_generation_space_used_at_start_of_incremental_(0), old_generation_space_used_at_start_of_incremental_(0),
steps_count_since_last_gc_(0),
steps_took_since_last_gc_(0),
should_hurry_(false), should_hurry_(false),
marking_speed_(0), marking_speed_(0),
allocated_(0), allocated_(0),
no_marking_scope_depth_(0), no_marking_scope_depth_(0),
unscanned_bytes_of_large_object_(0) { unscanned_bytes_of_large_object_(0) {}
}
void IncrementalMarking::TearDown() { void IncrementalMarking::TearDown() {
...@@ -655,6 +658,9 @@ void IncrementalMarking::UpdateMarkingDequeAfterScavenge() { ...@@ -655,6 +658,9 @@ void IncrementalMarking::UpdateMarkingDequeAfterScavenge() {
} }
} }
marking_deque_.set_top(new_top); marking_deque_.set_top(new_top);
steps_took_since_last_gc_ = 0;
steps_count_since_last_gc_ = 0;
} }
...@@ -889,6 +895,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes, ...@@ -889,6 +895,7 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
} }
steps_count_++; steps_count_++;
steps_count_since_last_gc_++;
bool speed_up = false; bool speed_up = false;
...@@ -957,7 +964,9 @@ void IncrementalMarking::Step(intptr_t allocated_bytes, ...@@ -957,7 +964,9 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
FLAG_print_cumulative_gc_stat) { FLAG_print_cumulative_gc_stat) {
double end = base::OS::TimeCurrentMillis(); double end = base::OS::TimeCurrentMillis();
double delta = (end - start); double delta = (end - start);
heap_->tracer()->AddIncrementalMarkingStep(delta); longest_step_ = Max(longest_step_, delta);
steps_took_ += delta;
steps_took_since_last_gc_ += delta;
heap_->AddMarkingTime(delta); heap_->AddMarkingTime(delta);
} }
} }
...@@ -965,10 +974,14 @@ void IncrementalMarking::Step(intptr_t allocated_bytes, ...@@ -965,10 +974,14 @@ void IncrementalMarking::Step(intptr_t allocated_bytes,
void IncrementalMarking::ResetStepCounters() { void IncrementalMarking::ResetStepCounters() {
steps_count_ = 0; steps_count_ = 0;
steps_took_ = 0;
longest_step_ = 0.0;
old_generation_space_available_at_start_of_incremental_ = old_generation_space_available_at_start_of_incremental_ =
SpaceLeftInOldSpace(); SpaceLeftInOldSpace();
old_generation_space_used_at_start_of_incremental_ = old_generation_space_used_at_start_of_incremental_ =
heap_->PromotedTotalSize(); heap_->PromotedTotalSize();
steps_count_since_last_gc_ = 0;
steps_took_since_last_gc_ = 0;
bytes_rescanned_ = 0; bytes_rescanned_ = 0;
marking_speed_ = kInitialMarkingSpeed; marking_speed_ = kInitialMarkingSpeed;
bytes_scanned_ = 0; bytes_scanned_ = 0;
......
...@@ -136,6 +136,16 @@ class IncrementalMarking { ...@@ -136,6 +136,16 @@ class IncrementalMarking {
inline void WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit); inline void WhiteToGreyAndPush(HeapObject* obj, MarkBit mark_bit);
inline int steps_count() { return steps_count_; }
inline double steps_took() { return steps_took_; }
inline double longest_step() { return longest_step_; }
inline int steps_count_since_last_gc() { return steps_count_since_last_gc_; }
inline double steps_took_since_last_gc() { return steps_took_since_last_gc_; }
inline void SetOldSpacePageFlags(MemoryChunk* chunk) { inline void SetOldSpacePageFlags(MemoryChunk* chunk) {
SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting()); SetOldSpacePageFlags(chunk, IsMarking(), IsCompacting());
} }
...@@ -216,8 +226,12 @@ class IncrementalMarking { ...@@ -216,8 +226,12 @@ class IncrementalMarking {
MarkingDeque marking_deque_; MarkingDeque marking_deque_;
int steps_count_; int steps_count_;
double steps_took_;
double longest_step_;
int64_t old_generation_space_available_at_start_of_incremental_; int64_t old_generation_space_available_at_start_of_incremental_;
int64_t old_generation_space_used_at_start_of_incremental_; int64_t old_generation_space_used_at_start_of_incremental_;
int steps_count_since_last_gc_;
double steps_took_since_last_gc_;
int64_t bytes_rescanned_; int64_t bytes_rescanned_;
bool should_hurry_; bool should_hurry_;
int marking_speed_; int marking_speed_;
......
...@@ -78,7 +78,6 @@ ...@@ -78,7 +78,6 @@
'test-fixed-dtoa.cc', 'test-fixed-dtoa.cc',
'test-flags.cc', 'test-flags.cc',
'test-func-name-inference.cc', 'test-func-name-inference.cc',
'test-gc-tracer.cc',
'test-global-handles.cc', 'test-global-handles.cc',
'test-global-object.cc', 'test-global-object.cc',
'test-hashing.cc', 'test-hashing.cc',
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <utility>
#include "src/v8.h"
#include "test/cctest/cctest.h"
using namespace v8::internal;
TEST(RingBufferPartialFill) {
const size_t max_size = 6;
typedef RingBuffer<size_t, max_size>::const_iterator Iter;
RingBuffer<size_t, max_size> ring_buffer;
CHECK(ring_buffer.empty());
CHECK_EQ(ring_buffer.size(), 0);
CHECK(ring_buffer.begin() == ring_buffer.end());
// Fill ring_buffer partially: [0, 1, 2]
for (size_t i = 0; i < max_size/2; i++)
ring_buffer.push_back(i);
CHECK(!ring_buffer.empty());
CHECK(ring_buffer.size() == max_size/2);
CHECK(ring_buffer.begin() != ring_buffer.end());
// Test forward itartion
size_t i = 0;
for (Iter iter = ring_buffer.begin(); iter != ring_buffer.end(); ++iter) {
CHECK(*iter == i);
++i;
}
CHECK_EQ(i, 3); // one past last element.
// Test backward iteration
i = 2;
Iter iter = ring_buffer.back();
while (true) {
CHECK(*iter == i);
if (iter == ring_buffer.begin())
break;
--iter;
--i;
}
CHECK_EQ(i, 0);
}
TEST(RingBufferWrapAround) {
const size_t max_size = 6;
typedef RingBuffer<size_t, max_size>::const_iterator Iter;
RingBuffer<size_t, max_size> ring_buffer;
// Fill ring_buffer (wrap around): [9, 10, 11, 12, 13, 14]
for (size_t i = 0; i < 2 * max_size + 3; i++)
ring_buffer.push_back(i);
CHECK(!ring_buffer.empty());
CHECK(ring_buffer.size() == max_size);
CHECK(ring_buffer.begin() != ring_buffer.end());
// Test forward iteration
size_t i = 9;
for (Iter iter = ring_buffer.begin(); iter != ring_buffer.end(); ++iter) {
CHECK(*iter == i);
++i;
}
CHECK_EQ(i, 15); // one past last element.
// Test backward iteration
i = 14;
Iter iter = ring_buffer.back();
while (true) {
CHECK(*iter == i);
if (iter == ring_buffer.begin())
break;
--iter;
--i;
}
CHECK_EQ(i, 9);
}
TEST(RingBufferPushFront) {
const size_t max_size = 6;
typedef RingBuffer<size_t, max_size>::const_iterator Iter;
RingBuffer<size_t, max_size> ring_buffer;
// Fill ring_buffer (wrap around): [14, 13, 12, 11, 10, 9]
for (size_t i = 0; i < 2 * max_size + 3; i++)
ring_buffer.push_front(i);
CHECK(!ring_buffer.empty());
CHECK(ring_buffer.size() == max_size);
CHECK(ring_buffer.begin() != ring_buffer.end());
// Test forward iteration
size_t i = 14;
for (Iter iter = ring_buffer.begin(); iter != ring_buffer.end(); ++iter) {
CHECK(*iter == i);
--i;
}
CHECK_EQ(i, 8); // one past last element.
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment