[turbofan] Add a mutex for recording compilation statistics

There was previously a race between different phases recording their
first entry -- and thus, their insert order -- on the main and
concurrent-compilation thread. This would later manifest as a segfault
when creating the sorted array of phases for --turbo-stats (as two
phases would have the same insert order and so there would be a gap in
the array).

Review-Url: https://codereview.chromium.org/2572713003
Cr-Commit-Position: refs/heads/master@{#41669}
This commit is contained in:
leszeks 2016-12-13 04:14:04 -08:00 committed by Commit bot
parent 449829b85c
commit 1df36a80de
2 changed files with 7 additions and 0 deletions

View File

@ -14,6 +14,8 @@ namespace internal {
void CompilationStatistics::RecordPhaseStats(const char* phase_kind_name,
const char* phase_name,
const BasicStats& stats) {
base::LockGuard<base::Mutex> guard(&record_mutex_);
std::string phase_name_str(phase_name);
auto it = phase_map_.find(phase_name_str);
if (it == phase_map_.end()) {
@ -26,6 +28,8 @@ void CompilationStatistics::RecordPhaseStats(const char* phase_kind_name,
void CompilationStatistics::RecordPhaseKindStats(const char* phase_kind_name,
const BasicStats& stats) {
base::LockGuard<base::Mutex> guard(&record_mutex_);
std::string phase_kind_name_str(phase_kind_name);
auto it = phase_kind_map_.find(phase_kind_name_str);
if (it == phase_kind_map_.end()) {
@ -39,6 +43,8 @@ void CompilationStatistics::RecordPhaseKindStats(const char* phase_kind_name,
void CompilationStatistics::RecordTotalStats(size_t source_size,
const BasicStats& stats) {
base::LockGuard<base::Mutex> guard(&record_mutex_);
source_size += source_size;
total_stats_.Accumulate(stats);
}

View File

@ -80,6 +80,7 @@ class CompilationStatistics final : public Malloced {
TotalStats total_stats_;
PhaseKindMap phase_kind_map_;
PhaseMap phase_map_;
base::Mutex record_mutex_;
DISALLOW_COPY_AND_ASSIGN(CompilationStatistics);
};