Commit 91a3517e authored by heimbuef's avatar heimbuef Committed by Commit bot

Added zone pool metrics to gc-trace.

Can be displayed in the external tool as well.

BUG=v8:5489

Review-Url: https://codereview.chromium.org/2392183004
Cr-Commit-Position: refs/heads/master@{#40166}
parent 08217e45
...@@ -1931,16 +1931,26 @@ void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) { ...@@ -1931,16 +1931,26 @@ void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) {
class VerboseAccountingAllocator : public AccountingAllocator { class VerboseAccountingAllocator : public AccountingAllocator {
public: public:
VerboseAccountingAllocator(Heap* heap, size_t sample_bytes) VerboseAccountingAllocator(Heap* heap, size_t allocation_sample_bytes,
: heap_(heap), last_memory_usage_(0), sample_bytes_(sample_bytes) {} size_t pool_sample_bytes)
: heap_(heap),
last_memory_usage_(0),
last_pool_size_(0),
allocation_sample_bytes_(allocation_sample_bytes),
pool_sample_bytes_(pool_sample_bytes) {}
v8::internal::Segment* GetSegment(size_t size) override { v8::internal::Segment* GetSegment(size_t size) override {
v8::internal::Segment* memory = AccountingAllocator::GetSegment(size); v8::internal::Segment* memory = AccountingAllocator::GetSegment(size);
if (memory) { if (memory) {
size_t current = GetCurrentMemoryUsage(); size_t malloced_current = GetCurrentMemoryUsage();
if (last_memory_usage_.Value() + sample_bytes_ < current) { size_t pooled_current = GetCurrentPoolSize();
PrintJSON(current);
last_memory_usage_.SetValue(current); if (last_memory_usage_.Value() + allocation_sample_bytes_ <
malloced_current ||
last_pool_size_.Value() + pool_sample_bytes_ < pooled_current) {
PrintJSON(malloced_current, pooled_current);
last_memory_usage_.SetValue(malloced_current);
last_pool_size_.SetValue(pooled_current);
} }
} }
return memory; return memory;
...@@ -1948,31 +1958,38 @@ class VerboseAccountingAllocator : public AccountingAllocator { ...@@ -1948,31 +1958,38 @@ class VerboseAccountingAllocator : public AccountingAllocator {
void ReturnSegment(v8::internal::Segment* memory) override { void ReturnSegment(v8::internal::Segment* memory) override {
AccountingAllocator::ReturnSegment(memory); AccountingAllocator::ReturnSegment(memory);
size_t current = GetCurrentMemoryUsage(); size_t malloced_current = GetCurrentMemoryUsage();
if (current + sample_bytes_ < last_memory_usage_.Value()) { size_t pooled_current = GetCurrentPoolSize();
PrintJSON(current);
last_memory_usage_.SetValue(current); if (malloced_current + allocation_sample_bytes_ <
last_memory_usage_.Value() ||
pooled_current + pool_sample_bytes_ < last_pool_size_.Value()) {
PrintJSON(malloced_current, pooled_current);
last_memory_usage_.SetValue(malloced_current);
last_pool_size_.SetValue(pooled_current);
} }
} }
private: private:
void PrintJSON(size_t sample) { void PrintJSON(size_t malloced, size_t pooled) {
// Note: Neither isolate, nor heap is locked, so be careful with accesses // Note: Neither isolate, nor heap is locked, so be careful with accesses
// as the allocator is potentially used on a concurrent thread. // as the allocator is potentially used on a concurrent thread.
double time = heap_->isolate()->time_millis_since_init(); double time = heap_->isolate()->time_millis_since_init();
PrintF( PrintF(
"{" "{"
"\"type\": \"malloced\", " "\"type\": \"zone\", "
"\"isolate\": \"%p\", " "\"isolate\": \"%p\", "
"\"time\": %f, " "\"time\": %f, "
"\"value\": %zu" "\"allocated\": %zu,"
"\"pooled\": %zu"
"}\n", "}\n",
reinterpret_cast<void*>(heap_->isolate()), time, sample); reinterpret_cast<void*>(heap_->isolate()), time, malloced, pooled);
} }
Heap* heap_; Heap* heap_;
base::AtomicNumber<size_t> last_memory_usage_; base::AtomicNumber<size_t> last_memory_usage_;
size_t sample_bytes_; base::AtomicNumber<size_t> last_pool_size_;
size_t allocation_sample_bytes_, pool_sample_bytes_;
}; };
Isolate::Isolate(bool enable_serializer) Isolate::Isolate(bool enable_serializer)
...@@ -2000,9 +2017,9 @@ Isolate::Isolate(bool enable_serializer) ...@@ -2000,9 +2017,9 @@ Isolate::Isolate(bool enable_serializer)
descriptor_lookup_cache_(NULL), descriptor_lookup_cache_(NULL),
handle_scope_implementer_(NULL), handle_scope_implementer_(NULL),
unicode_cache_(NULL), unicode_cache_(NULL),
allocator_(FLAG_trace_gc_object_stats allocator_(FLAG_trace_gc_object_stats ? new VerboseAccountingAllocator(
? new VerboseAccountingAllocator(&heap_, 256 * KB) &heap_, 256 * KB, 128 * KB)
: new AccountingAllocator()), : new AccountingAllocator()),
inner_pointer_to_code_cache_(NULL), inner_pointer_to_code_cache_(NULL),
global_handles_(NULL), global_handles_(NULL),
eternal_handles_(NULL), eternal_handles_(NULL),
......
...@@ -84,6 +84,10 @@ size_t AccountingAllocator::GetMaxMemoryUsage() const { ...@@ -84,6 +84,10 @@ size_t AccountingAllocator::GetMaxMemoryUsage() const {
return base::NoBarrier_Load(&max_memory_usage_); return base::NoBarrier_Load(&max_memory_usage_);
} }
size_t AccountingAllocator::GetCurrentPoolSize() const {
return base::NoBarrier_Load(&current_pool_size_);
}
Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) { Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) {
if (requested_size > (1 << kMaxSegmentSizePower)) { if (requested_size > (1 << kMaxSegmentSizePower)) {
return nullptr; return nullptr;
...@@ -106,7 +110,8 @@ Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) { ...@@ -106,7 +110,8 @@ Segment* AccountingAllocator::GetSegmentFromPool(size_t requested_size) {
segment->set_next(nullptr); segment->set_next(nullptr);
unused_segments_sizes[power]--; unused_segments_sizes[power]--;
unused_segments_size_ -= segment->size(); base::NoBarrier_AtomicIncrement(
&current_pool_size_, -static_cast<base::AtomicWord>(segment->size()));
} }
} }
...@@ -139,7 +144,7 @@ bool AccountingAllocator::AddSegmentToPool(Segment* segment) { ...@@ -139,7 +144,7 @@ bool AccountingAllocator::AddSegmentToPool(Segment* segment) {
segment->set_next(unused_segments_heads_[power]); segment->set_next(unused_segments_heads_[power]);
unused_segments_heads_[power] = segment; unused_segments_heads_[power] = segment;
unused_segments_size_ += size; base::NoBarrier_AtomicIncrement(&current_pool_size_, size);
unused_segments_sizes[power]++; unused_segments_sizes[power]++;
} }
......
...@@ -59,12 +59,11 @@ class V8_EXPORT_PRIVATE AccountingAllocator { ...@@ -59,12 +59,11 @@ class V8_EXPORT_PRIVATE AccountingAllocator {
size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower];
size_t unused_segments_size_ = 0;
base::Mutex unused_segments_mutex_; base::Mutex unused_segments_mutex_;
base::AtomicWord current_memory_usage_ = 0; base::AtomicWord current_memory_usage_ = 0;
base::AtomicWord max_memory_usage_ = 0; base::AtomicWord max_memory_usage_ = 0;
base::AtomicWord current_pool_size_ = 0;
base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; base::AtomicValue<MemoryPressureLevel> memory_pressure_level_;
......
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