Commit ef059df6 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[handles] Check whether main thread local heap is parked on dereference

When dereferencing handles check whether the main thread is parked
similar to background threads.

Bug: chromium:1152995
Change-Id: Ic79680f1b1c49f5f0ad872d6377ca45920a18b98
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2575061Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarGeorg Neis (ooo until January 5) <neis@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71760}
parent c170e0cf
......@@ -3295,6 +3295,7 @@ bool PipelineImpl::SelectInstructions(Linkage* linkage) {
DCHECK_NOT_NULL(data->schedule());
if (FLAG_turbo_profiling) {
UnparkedScopeIfNeeded unparked_scope(data->broker());
data->info()->set_profiler_data(BasicBlockInstrumentor::Instrument(
info(), data->graph(), data->schedule(), data->isolate()));
}
......
......@@ -4770,6 +4770,11 @@ LocalHeap* Isolate::main_thread_local_heap() {
return main_thread_local_isolate()->heap();
}
LocalHeap* Isolate::CurrentLocalHeap() {
LocalHeap* local_heap = LocalHeap::Current();
return local_heap ? local_heap : main_thread_local_heap();
}
// |chunk| is either a Page or an executable LargePage.
void Isolate::RemoveCodeMemoryChunk(MemoryChunk* chunk) {
// We only keep track of individual code pages/allocations if we are on arm32,
......
......@@ -1638,6 +1638,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
}
LocalHeap* main_thread_local_heap();
LocalHeap* CurrentLocalHeap();
#ifdef V8_HEAP_SANDBOX
ExternalPointerTable& external_pointer_table() {
......
......@@ -46,8 +46,9 @@ bool HandleBase::IsDereferenceAllowed() const {
if (isolate->IsBuiltinsTableHandleLocation(location_)) return true;
if (!AllowHandleDereference::IsAllowed()) return false;
LocalHeap* local_heap = LocalHeap::Current();
if (FLAG_local_heaps && local_heap) {
if (FLAG_local_heaps) {
LocalHeap* local_heap = isolate->CurrentLocalHeap();
// Local heap can't access handles when parked
if (!local_heap->IsHandleDereferenceAllowed()) {
StdoutStream{} << "Cannot dereference handle owned by "
......@@ -55,17 +56,19 @@ bool HandleBase::IsDereferenceAllowed() const {
return false;
}
// The current thread owns the handle and thus can dereference it.
return local_heap->ContainsPersistentHandle(location_) ||
local_heap->ContainsLocalHandle(location_);
// We are pretty strict with handle dereferences on background threads: A
// background local heap is only allowed to dereference its own local or
// persistent handles.
if (!local_heap->is_main_thread()) {
// The current thread owns the handle and thus can dereference it.
return local_heap->ContainsPersistentHandle(location_) ||
local_heap->ContainsLocalHandle(location_);
}
}
// If the local_heap is null, we're on the main thread -- if we were to check
// main thread HandleScopes here, we should additionally check the main-thread
// LocalHeap.
// If LocalHeap::Current() is null, we're on the main thread -- if we were to
// check main thread HandleScopes here, we should additionally check the
// main-thread LocalHeap.
DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
if (FLAG_local_heaps) {
DCHECK_NOT_NULL(isolate->main_thread_local_heap());
}
// TODO(leszeks): Check if the main thread owns this handle.
return true;
......
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