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

Unified Diff: src/heap/gc-tracer.cc

Issue 2310143002: [heap] Introduce enum of garbage collection reasons. (Closed)
Patch Set: fix win Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/heap/gc-tracer.cc
diff --git a/src/heap/gc-tracer.cc b/src/heap/gc-tracer.cc
index 98be41d3693be9e79c2faf20e077f7d13093668f..5ac5fe1c6c6c3760dbda85b0ca7b73eb943741fc 100644
--- a/src/heap/gc-tracer.cc
+++ b/src/heap/gc-tracer.cc
@@ -57,7 +57,7 @@ const char* GCTracer::Scope::Name(ScopeId id) {
return "(unknown)";
}
-GCTracer::Event::Event(Type type, const char* gc_reason,
+GCTracer::Event::Event(Type type, GarbageCollectionReason gc_reason,
const char* collector_reason)
: type(type),
gc_reason(gc_reason),
@@ -110,7 +110,7 @@ const char* GCTracer::Event::TypeName(bool short_name) const {
GCTracer::GCTracer(Heap* heap)
: heap_(heap),
- current_(Event::START, nullptr, nullptr),
+ current_(Event::START, GarbageCollectionReason::kUnknown, nullptr),
previous_(current_),
previous_incremental_mark_compactor_event_(current_),
cumulative_incremental_marking_bytes_(0),
@@ -130,7 +130,7 @@ GCTracer::GCTracer(Heap* heap)
}
void GCTracer::ResetForTesting() {
- current_ = Event(Event::START, NULL, NULL);
+ current_ = Event(Event::START, GarbageCollectionReason::kTesting, nullptr);
current_.end_time = heap_->MonotonicallyIncreasingTimeInMs();
previous_ = previous_incremental_mark_compactor_event_ = current_;
cumulative_incremental_marking_bytes_ = 0.0;
@@ -162,7 +162,8 @@ void GCTracer::ResetForTesting() {
start_counter_ = 0;
}
-void GCTracer::Start(GarbageCollector collector, const char* gc_reason,
+void GCTracer::Start(GarbageCollector collector,
+ GarbageCollectionReason gc_reason,
const char* collector_reason) {
start_counter_++;
if (start_counter_ != 1) return;
@@ -411,6 +412,57 @@ void GCTracer::Output(const char* format, ...) const {
heap_->AddToRingBuffer(buffer.start());
}
+const char* GCTracer::GarbageCollectionReasonToString(
+ GarbageCollectionReason gc_reason) {
+ switch (gc_reason) {
+ case GarbageCollectionReason::kAllocationFailure:
+ return "allocation failure";
+ case GarbageCollectionReason::kAllocationLimit:
+ return "allocation limit";
+ case GarbageCollectionReason::kContextDisposal:
+ return "context disposal";
+ case GarbageCollectionReason::kCountersExtension:
+ return "counters extension";
+ case GarbageCollectionReason::kDebugger:
+ return "debugger";
+ case GarbageCollectionReason::kDeserializer:
+ return "deserialize";
+ case GarbageCollectionReason::kExternalMemoryPressure:
+ return "external memory pressure";
+ case GarbageCollectionReason::kFinalizeMarkingViaStackGuard:
+ return "finalize incremental marking via stack guard";
+ case GarbageCollectionReason::kFinalizeMarkingViaTask:
+ return "finalize incremental marking via task";
+ case GarbageCollectionReason::kFullHashtable:
+ return "full hash-table";
+ case GarbageCollectionReason::kHeapProfiler:
+ return "heap profiler";
+ case GarbageCollectionReason::kIdleTask:
+ return "idle task";
+ case GarbageCollectionReason::kLastResort:
+ return "last resort";
+ case GarbageCollectionReason::kLowMemoryNotification:
+ return "low memory notification";
+ case GarbageCollectionReason::kMakeHeapIterable:
+ return "make heap iterable";
+ case GarbageCollectionReason::kMemoryPressure:
+ return "memory pressure";
+ case GarbageCollectionReason::kMemoryReducer:
+ return "memory reducer";
+ case GarbageCollectionReason::kRuntime:
+ return "runtime";
+ case GarbageCollectionReason::kSamplingProfiler:
+ return "sampling profiler";
+ case GarbageCollectionReason::kSnapshotCreator:
+ return "snapshot creator";
+ case GarbageCollectionReason::kTesting:
+ return "testing";
+ case GarbageCollectionReason::kUnknown:
+ return "unknown";
+ }
+ UNREACHABLE();
+ return "";
+}
void GCTracer::Print() const {
double duration = current_.end_time - current_.start_time;
@@ -443,7 +495,7 @@ void GCTracer::Print() const {
static_cast<double>(current_.end_object_size) / MB,
static_cast<double>(current_.end_memory_size) / MB, duration,
TotalExternalTime(), incremental_buffer,
- current_.gc_reason != nullptr ? current_.gc_reason : "",
+ GarbageCollectionReasonToString(current_.gc_reason),
current_.collector_reason != nullptr ? current_.collector_reason : "");
}
« src/heap/gc-tracer.h ('K') | « src/heap/gc-tracer.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698