Commit 89e4972c authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Move duplicate CappedSizeInKB() to header file for sharing

Some jumbo builds broke because of too many CappedSizeInKB so moving
it to heap.h to unbreak the builds. It's a small inlined method.
The moved function is not using std::min to avoid including
<algorithm> in heap.h and potentially causing a measurable
build time regression.

TBR=mlippautz@chromium.org,haraken@chromium.org

Bug: 840789
Change-Id: I4e4bf3989235c6e7274a56f5c10823d8bb37a4df
Reviewed-on: https://chromium-review.googlesource.com/1090839Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarDaniel Bratell <bratell@opera.com>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#565289}
parent 903fd04e
...@@ -352,15 +352,6 @@ void ThreadHeap::ReportMemoryUsageHistogram() { ...@@ -352,15 +352,6 @@ void ThreadHeap::ReportMemoryUsageHistogram() {
} }
} }
namespace {
size_t CappedSizeInKB(size_t size) {
return std::min(size / 1024,
static_cast<size_t>(std::numeric_limits<int>::max()));
}
} // namespace
void ThreadHeap::ReportMemoryUsageForTracing() { void ThreadHeap::ReportMemoryUsageForTracing() {
bool gc_tracing_enabled; bool gc_tracing_enabled;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc"), TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc"),
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_H_
#include <limits>
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
...@@ -601,6 +602,15 @@ inline bool ThreadHeap::IsNormalArenaIndex(int index) { ...@@ -601,6 +602,15 @@ inline bool ThreadHeap::IsNormalArenaIndex(int index) {
index <= BlinkGC::kNormalPage4ArenaIndex; index <= BlinkGC::kNormalPage4ArenaIndex;
} }
// Helper function to convert a byte count to a KB count, capping at
// INT_MAX if the number is larger than that. Useful for reporting
// purposes.
constexpr size_t CappedSizeInKB(size_t size) {
size_t size_kb = size / 1024;
size_t limit = std::numeric_limits<int>::max();
return size_kb > limit ? limit : size_kb;
}
#define DECLARE_EAGER_FINALIZATION_OPERATOR_NEW() \ #define DECLARE_EAGER_FINALIZATION_OPERATOR_NEW() \
public: \ public: \
GC_PLUGIN_IGNORE("491488") \ GC_PLUGIN_IGNORE("491488") \
......
...@@ -409,7 +409,7 @@ double ThreadState::HeapGrowingRate() { ...@@ -409,7 +409,7 @@ double ThreadState::HeapGrowingRate() {
estimated_size > 0 ? 1.0 * current_size / estimated_size : 100; estimated_size > 0 ? 1.0 * current_size / estimated_size : 100;
TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"),
"ThreadState::heapEstimatedSizeKB", "ThreadState::heapEstimatedSizeKB",
std::min(estimated_size / 1024, static_cast<size_t>(INT_MAX))); CappedSizeInKB(estimated_size));
TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"),
"ThreadState::heapGrowingRate", "ThreadState::heapGrowingRate",
static_cast<int>(100 * growing_rate)); static_cast<int>(100 * growing_rate));
...@@ -426,7 +426,7 @@ double ThreadState::PartitionAllocGrowingRate() { ...@@ -426,7 +426,7 @@ double ThreadState::PartitionAllocGrowingRate() {
estimated_size > 0 ? 1.0 * current_size / estimated_size : 100; estimated_size > 0 ? 1.0 * current_size / estimated_size : 100;
TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"),
"ThreadState::partitionAllocEstimatedSizeKB", "ThreadState::partitionAllocEstimatedSizeKB",
std::min(estimated_size / 1024, static_cast<size_t>(INT_MAX))); CappedSizeInKB(estimated_size));
TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"), TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink_gc"),
"ThreadState::partitionAllocGrowingRate", "ThreadState::partitionAllocGrowingRate",
static_cast<int>(100 * growing_rate)); static_cast<int>(100 * growing_rate));
...@@ -1002,11 +1002,6 @@ BlinkGCObserver::~BlinkGCObserver() { ...@@ -1002,11 +1002,6 @@ BlinkGCObserver::~BlinkGCObserver() {
namespace { namespace {
size_t CappedSizeInKB(size_t size) {
return std::min(size / 1024,
static_cast<size_t>(std::numeric_limits<int>::max()));
}
void UpdateHistogramsAndCounters(const ThreadHeapStatsCollector::Event& event) { void UpdateHistogramsAndCounters(const ThreadHeapStatsCollector::Event& event) {
DEFINE_STATIC_LOCAL(EnumerationHistogram, gc_reason_histogram, DEFINE_STATIC_LOCAL(EnumerationHistogram, gc_reason_histogram,
("BlinkGC.GCReason", BlinkGC::kLastGCReason + 1)); ("BlinkGC.GCReason", BlinkGC::kLastGCReason + 1));
......
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