[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:
parent
527d55680f
commit
c408123d75
@ -420,8 +420,7 @@ void RuntimeCallTimer::Snapshot() {
|
||||
Resume(now);
|
||||
}
|
||||
|
||||
RuntimeCallStats::RuntimeCallStats()
|
||||
: in_use_(false), thread_id_(ThreadId::Current()) {
|
||||
RuntimeCallStats::RuntimeCallStats() : in_use_(false) {
|
||||
static const char* const kNames[] = {
|
||||
#define CALL_BUILTIN_COUNTER(name) "GC_" #name,
|
||||
FOR_EACH_GC_COUNTER(CALL_BUILTIN_COUNTER) //
|
||||
@ -477,7 +476,7 @@ const int RuntimeCallStats::counters_count =
|
||||
// static
|
||||
void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
|
||||
CounterId counter_id) {
|
||||
DCHECK(ThreadId::Current().Equals(stats->thread_id()));
|
||||
DCHECK(stats->IsCalledOnTheSameThread());
|
||||
RuntimeCallCounter* counter = &(stats->*counter_id);
|
||||
DCHECK(counter->name() != nullptr);
|
||||
timer->Start(counter, stats->current_timer_.Value());
|
||||
@ -487,7 +486,7 @@ void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer,
|
||||
|
||||
// static
|
||||
void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) {
|
||||
DCHECK(ThreadId::Current().Equals(stats->thread_id()));
|
||||
DCHECK(stats->IsCalledOnTheSameThread());
|
||||
if (stats->current_timer_.Value() != timer) {
|
||||
// The branch is added to catch a crash crbug.com/760649
|
||||
EmbeddedVector<char, 200> text;
|
||||
@ -521,6 +520,13 @@ void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats,
|
||||
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) {
|
||||
RuntimeCallStatEntries entries;
|
||||
if (current_timer_.Value() != nullptr) {
|
||||
|
@ -937,6 +937,7 @@ class RuntimeCallStats final : public ZoneObject {
|
||||
RuntimeCallTimer* current_timer() { return current_timer_.Value(); }
|
||||
RuntimeCallCounter* current_counter() { return current_counter_.Value(); }
|
||||
bool InUse() { return in_use_; }
|
||||
bool IsCalledOnTheSameThread();
|
||||
|
||||
private:
|
||||
// Top of a stack of active timers.
|
||||
|
Loading…
Reference in New Issue
Block a user