Commit f073a20b authored by kschimpf's avatar kschimpf Committed by Commit Bot

Localize counter class member functions.

This CL takes advantage of the fact that StatsCounter is now local to
the Counters class. This includes:

1) Method StatsTable::SetCreateHistogramFunction() was only called in
one spot (in api.cc), which also called Counters::ResetHistograms()
and Counters::InitializeHistorgram(). InitializeHistogram can be
folded into Histogram.Reset().

2) Since Histogram::Reset() now regenerats the histogram, we no longer
need the field lookup_done_. Therefore there is no longer a race
between updating ptr_ and lookup_done_, making the Histogram class
thread safe.

3) Made the constructors of several classes private (except for class
Counters), minimizing the scope that they are used. When the couldn't
be moved, add comment that they were public only for test cases.

4) Removed the need for a mutex lock on StatsCounter::Reset(), since
it is now guaranteed to only be called when
StatsTable::SetCounterFunction() is called.

BUG=v8:6361
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_rel_ng

Review-Url: https://codereview.chromium.org/2918703002
Cr-Commit-Position: refs/heads/master@{#45791}
parent fe048410
......@@ -8730,23 +8730,20 @@ void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
void Isolate::SetCounterFunction(CounterLookupCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->stats_table()->SetCounterFunction(callback);
isolate->counters()->ResetCounterFunction(callback);
}
void Isolate::SetCreateHistogramFunction(CreateHistogramCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->stats_table()->SetCreateHistogramFunction(callback);
isolate->InitializeLoggingAndCounters();
isolate->counters()->ResetHistograms();
isolate->counters()->InitializeHistograms();
isolate->counters()->ResetCreateHistogramFunction(callback);
}
void Isolate::SetAddHistogramSampleFunction(
AddHistogramSampleCallback callback) {
reinterpret_cast<i::Isolate*>(this)
->stats_table()
->counters()
->SetAddHistogramSampleFunction(callback);
}
......
......@@ -16,25 +16,21 @@ namespace v8 {
namespace internal {
StatsTable::StatsTable(Counters* counters)
: counters_(counters),
lookup_function_(NULL),
: lookup_function_(NULL),
create_histogram_function_(NULL),
add_histogram_sample_function_(NULL) {}
void StatsTable::SetCounterFunction(CounterLookupCallback f) {
lookup_function_ = f;
counters_->ResetCounters();
}
int* StatsCounterBase::FindLocationInStatsTable() const {
return counters_->stats_table()->FindLocation(name_);
return counters_->FindLocation(name_);
}
StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters,
const char* name)
: StatsCounterBase(counters, name) {
GetPtr();
}
: StatsCounterBase(counters, name) {}
void StatsCounterThreadSafe::Set(int Value) {
if (ptr_) {
......@@ -71,21 +67,14 @@ void StatsCounterThreadSafe::Decrement(int value) {
}
}
int* StatsCounterThreadSafe::GetPtr() {
base::LockGuard<base::Mutex> Guard(&mutex_);
ptr_ = FindLocationInStatsTable();
return ptr_;
}
void Histogram::AddSample(int sample) {
if (Enabled()) {
counters_->stats_table()->AddHistogramSample(histogram_, sample);
counters_->AddHistogramSample(histogram_, sample);
}
}
void* Histogram::CreateHistogram() const {
return counters_->stats_table()->CreateHistogram(name_, min_, max_,
num_buckets_);
return counters_->CreateHistogram(name_, min_, max_, num_buckets_);
}
......@@ -257,7 +246,9 @@ Counters::Counters(Isolate* isolate)
}
}
void Counters::ResetCounters() {
void Counters::ResetCounterFunction(CounterLookupCallback f) {
stats_table_.SetCounterFunction(f);
#define SC(name, caption) name##_.Reset();
STATS_COUNTER_LIST_1(SC)
STATS_COUNTER_LIST_2(SC)
......@@ -292,8 +283,9 @@ void Counters::ResetCounters() {
#undef SC
}
void Counters::ResetCreateHistogramFunction(CreateHistogramCallback f) {
stats_table_.SetCreateHistogramFunction(f);
void Counters::ResetHistograms() {
#define HR(name, caption, min, max, num_buckets) name##_.Reset();
HISTOGRAM_RANGE_LIST(HR)
#undef HR
......@@ -316,29 +308,6 @@ void Counters::ResetHistograms() {
#undef HM
}
void Counters::InitializeHistograms() {
#define HR(name, caption, min, max, num_buckets) name##_.Enabled();
HISTOGRAM_RANGE_LIST(HR)
#undef HR
#define HT(name, caption, max, res) name##_.Enabled();
HISTOGRAM_TIMER_LIST(HT)
#undef HT
#define AHT(name, caption) name##_.Enabled();
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
#undef AHT
#define HP(name, caption) name##_.Enabled();
HISTOGRAM_PERCENTAGE_LIST(HP)
#undef HP
#define HM(name, caption) name##_.Enabled();
HISTOGRAM_LEGACY_MEMORY_LIST(HM)
HISTOGRAM_MEMORY_LIST(HM)
#undef HM
}
class RuntimeCallStatEntries {
public:
void Print(std::ostream& os) {
......
This diff is collapsed.
......@@ -2290,7 +2290,6 @@ Isolate::Isolate(bool enable_serializer)
runtime_profiler_(NULL),
compilation_cache_(NULL),
logger_(NULL),
stats_table_(NULL),
load_stub_cache_(NULL),
store_stub_cache_(NULL),
code_aging_helper_(NULL),
......@@ -2544,7 +2543,6 @@ Isolate::~Isolate() {
store_stub_cache_ = NULL;
delete code_aging_helper_;
code_aging_helper_ = NULL;
stats_table_ = NULL;
delete materialized_object_store_;
materialized_object_store_ = NULL;
......@@ -2852,16 +2850,6 @@ bool Isolate::Init(Deserializer* des) {
}
// Initialized lazily to allow early
// v8::V8::SetAddHistogramSampleFunction calls.
StatsTable* Isolate::stats_table() {
if (stats_table_ != nullptr) return stats_table_;
InitializeCounters();
stats_table_ = counters_shared_->stats_table();
return stats_table_;
}
void Isolate::Enter() {
Isolate* current_isolate = NULL;
PerIsolateThreadData* current_data = CurrentPerIsolateThreadData();
......
......@@ -883,7 +883,6 @@ class Isolate {
}
StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; }
StatsTable* stats_table();
StubCache* load_stub_cache() { return load_stub_cache_; }
StubCache* store_stub_cache() { return store_stub_cache_; }
CodeAgingHelper* code_aging_helper() { return code_aging_helper_; }
......@@ -1436,7 +1435,6 @@ class Isolate {
base::RecursiveMutex break_access_;
Logger* logger_;
StackGuard stack_guard_;
StatsTable* stats_table_;
StubCache* load_stub_cache_;
StubCache* store_stub_cache_;
CodeAgingHelper* code_aging_helper_;
......
......@@ -28,9 +28,7 @@ class MockHistogram : public Histogram {
class AggregatedMemoryHistogramTest : public ::testing::Test {
public:
AggregatedMemoryHistogramTest() {
aggregated_ = AggregatedMemoryHistogram<MockHistogram>(&mock_);
}
AggregatedMemoryHistogramTest() : aggregated_(&mock_) {}
virtual ~AggregatedMemoryHistogramTest() {}
void AddSample(double current_ms, double current_value) {
......
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