Commit 8e8d61b3 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[offthread] Pin OffThreadIsolate to a given thread

Previously OffThreadIsolates set their thread-id on construction. This
thread-id could later be used in DCHECKs, comparing it against the
current thread's id.

However, OffThreadIsolates are created on the main thread (as they need
access to the Isolate and especially Heap for initialization). So, the
thread-id was actually not the background thread's id.

Now, OffThreadIsolate has a PinToCurrentThread method which should be
called on whichever thread wants to actually use it. This pinning can
only be done once, and the OffThreadIsolate is considered invalid before
this method is called.

Bug: chromium:1011762
Change-Id: Ie9d7838152683aea2a326a4e5d1dbd59a747131f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2110016
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66864}
parent 3ea7ecaf
......@@ -1285,6 +1285,8 @@ void BackgroundCompileTask::Run() {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.FinalizeCodeBackground");
off_thread_isolate_->PinToCurrentThread();
OffThreadHandleScope handle_scope(off_thread_isolate_.get());
// We don't have the script source or the script origin yet, so use a few
......
......@@ -15,7 +15,6 @@ OffThreadIsolate::OffThreadIsolate(Isolate* isolate, Zone* zone)
: HiddenOffThreadFactory(isolate),
isolate_(isolate),
logger_(new OffThreadLogger()),
thread_id_(ThreadId::Current()),
handle_zone_(zone) {}
OffThreadIsolate::~OffThreadIsolate() { delete logger_; }
......@@ -37,5 +36,10 @@ bool OffThreadIsolate::is_collecting_type_profile() {
return isolate_->is_collecting_type_profile();
}
void OffThreadIsolate::PinToCurrentThread() {
DCHECK(!thread_id_.IsValid());
thread_id_ = ThreadId::Current();
}
} // namespace internal
} // namespace v8
......@@ -78,6 +78,7 @@ class V8_EXPORT_PRIVATE OffThreadIsolate final
OffThreadLogger* logger() { return logger_; }
void PinToCurrentThread();
ThreadId thread_id() { return thread_id_; }
private:
......
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