[runtime-call-stats] Fix the threading check in debug mode.

The RuntimeCallStats object happen to be created on the main thread,
but then got used in a worker. Make sure the thread checks do not
fire false positives in this case.

BUG=chromium:760649

Change-Id: I8f2a2b4d1da1bc48416987ea378688ec15b9d955
Reviewed-on: https://chromium-review.googlesource.com/706181
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48409}
This commit is contained in:
Alexei Filippov 2017-10-06 17:28:30 -07:00 committed by Commit Bot
parent 527d55680f
commit c408123d75
2 changed files with 11 additions and 4 deletions

View File

@ -420,8 +420,7 @@ void RuntimeCallTimer::Snapshot() {
Resume(now); Resume(now);
} }
RuntimeCallStats::RuntimeCallStats() RuntimeCallStats::RuntimeCallStats() : in_use_(false) {
: in_use_(false), thread_id_(ThreadId::Current()) {
static const char* const kNames[] = { static const char* const kNames[] = {
#define CALL_BUILTIN_COUNTER(name) "GC_" #name, #define CALL_BUILTIN_COUNTER(name) "GC_" #name,
FOR_EACH_GC_COUNTER(CALL_BUILTIN_COUNTER) // FOR_EACH_GC_COUNTER(CALL_BUILTIN_COUNTER) //
@ -477,7 +476,7 @@ const int RuntimeCallStats::counters_count =
// static // static
void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
CounterId counter_id) { CounterId counter_id) {
DCHECK(ThreadId::Current().Equals(stats->thread_id())); DCHECK(stats->IsCalledOnTheSameThread());
RuntimeCallCounter* counter = &(stats->*counter_id); RuntimeCallCounter* counter = &(stats->*counter_id);
DCHECK(counter->name() != nullptr); DCHECK(counter->name() != nullptr);
timer->Start(counter, stats->current_timer_.Value()); timer->Start(counter, stats->current_timer_.Value());
@ -487,7 +486,7 @@ void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
// static // static
void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
DCHECK(ThreadId::Current().Equals(stats->thread_id())); DCHECK(stats->IsCalledOnTheSameThread());
if (stats->current_timer_.Value() != timer) { if (stats->current_timer_.Value() != timer) {
// The branch is added to catch a crash crbug.com/760649 // The branch is added to catch a crash crbug.com/760649
EmbeddedVector<char, 200> text; EmbeddedVector<char, 200> text;
@ -521,6 +520,13 @@ void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats,
stats->current_counter_.SetValue(counter); stats->current_counter_.SetValue(counter);
} }
bool RuntimeCallStats::IsCalledOnTheSameThread() {
if (!thread_id_.Equals(ThreadId::Invalid()))
return thread_id_.Equals(ThreadId::Current());
thread_id_ = ThreadId::Current();
return true;
}
void RuntimeCallStats::Print(std::ostream& os) { void RuntimeCallStats::Print(std::ostream& os) {
RuntimeCallStatEntries entries; RuntimeCallStatEntries entries;
if (current_timer_.Value() != nullptr) { if (current_timer_.Value() != nullptr) {

View File

@ -937,6 +937,7 @@ class RuntimeCallStats final : public ZoneObject {
RuntimeCallTimer* current_timer() { return current_timer_.Value(); } RuntimeCallTimer* current_timer() { return current_timer_.Value(); }
RuntimeCallCounter* current_counter() { return current_counter_.Value(); } RuntimeCallCounter* current_counter() { return current_counter_.Value(); }
bool InUse() { return in_use_; } bool InUse() { return in_use_; }
bool IsCalledOnTheSameThread();
private: private:
// Top of a stack of active timers. // Top of a stack of active timers.