Commit 28580740 authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Relax DCHECK in TRACE_GC

We might run TRACE_GC with ThreadKind::kMain not only on each isolate's
main thread but also on the shared isolate's thread during a shared GC.
The DCHECK is too restrictive for the latter case. This is safe because
the shared GC will stop all main threads before starting its work.

Bug: v8:11708
Change-Id: I1f40140d6502b1ec797dfa783fb693ed213efb3b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3380522Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78588}
parent 36d767ac
......@@ -72,7 +72,9 @@ GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope, ThreadKind thread_kind)
#ifdef V8_RUNTIME_CALL_STATS
if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
if (thread_kind_ == ThreadKind::kMain) {
DCHECK_EQ(tracer_->heap_->isolate()->thread_id(), ThreadId::Current());
#if DEBUG
AssertMainThread();
#endif // DEBUG
runtime_stats_ =
tracer_->heap_->isolate()->counters()->runtime_call_stats();
runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope));
......@@ -89,7 +91,10 @@ GCTracer::Scope::~Scope() {
double duration_ms = tracer_->MonotonicallyIncreasingTimeInMs() - start_time_;
if (thread_kind_ == ThreadKind::kMain) {
DCHECK_EQ(tracer_->heap_->isolate()->thread_id(), ThreadId::Current());
#if DEBUG
AssertMainThread();
#endif // DEBUG
tracer_->AddScopeSample(scope_, duration_ms);
if (scope_ == ScopeId::MC_INCREMENTAL ||
scope_ == ScopeId::MC_INCREMENTAL_START ||
......@@ -110,6 +115,19 @@ GCTracer::Scope::~Scope() {
#endif // defined(V8_RUNTIME_CALL_STATS)
}
#if DEBUG
void GCTracer::Scope::AssertMainThread() {
Isolate* isolate = tracer_->heap_->isolate();
Isolate* shared_isolate = isolate->shared_isolate();
ThreadId thread_id = ThreadId::Current();
// Either run on isolate's main thread or on the current main thread of the
// shared isolate during shared GCs.
DCHECK(isolate->thread_id() == thread_id ||
(shared_isolate && shared_isolate->thread_id() == thread_id));
}
#endif // DEBUG
const char* GCTracer::Scope::Name(ScopeId id) {
#define CASE(scope) \
case Scope::scope: \
......
......@@ -112,6 +112,10 @@ class V8_EXPORT_PRIVATE GCTracer {
static bool NeedsYoungEpoch(ScopeId id);
private:
#if DEBUG
void AssertMainThread();
#endif // DEBUG
GCTracer* tracer_;
ScopeId scope_;
ThreadKind thread_kind_;
......
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