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) { ...@@ -3295,6 +3295,7 @@ bool PipelineImpl::SelectInstructions(Linkage* linkage) {
DCHECK_NOT_NULL(data->schedule()); DCHECK_NOT_NULL(data->schedule());
if (FLAG_turbo_profiling) { if (FLAG_turbo_profiling) {
UnparkedScopeIfNeeded unparked_scope(data->broker());
data->info()->set_profiler_data(BasicBlockInstrumentor::Instrument( data->info()->set_profiler_data(BasicBlockInstrumentor::Instrument(
info(), data->graph(), data->schedule(), data->isolate())); info(), data->graph(), data->schedule(), data->isolate()));
} }
......
...@@ -4770,6 +4770,11 @@ LocalHeap* Isolate::main_thread_local_heap() { ...@@ -4770,6 +4770,11 @@ LocalHeap* Isolate::main_thread_local_heap() {
return main_thread_local_isolate()->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. // |chunk| is either a Page or an executable LargePage.
void Isolate::RemoveCodeMemoryChunk(MemoryChunk* chunk) { void Isolate::RemoveCodeMemoryChunk(MemoryChunk* chunk) {
// We only keep track of individual code pages/allocations if we are on arm32, // 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 { ...@@ -1638,6 +1638,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
} }
LocalHeap* main_thread_local_heap(); LocalHeap* main_thread_local_heap();
LocalHeap* CurrentLocalHeap();
#ifdef V8_HEAP_SANDBOX #ifdef V8_HEAP_SANDBOX
ExternalPointerTable& external_pointer_table() { ExternalPointerTable& external_pointer_table() {
......
...@@ -46,8 +46,9 @@ bool HandleBase::IsDereferenceAllowed() const { ...@@ -46,8 +46,9 @@ bool HandleBase::IsDereferenceAllowed() const {
if (isolate->IsBuiltinsTableHandleLocation(location_)) return true; if (isolate->IsBuiltinsTableHandleLocation(location_)) return true;
if (!AllowHandleDereference::IsAllowed()) return false; if (!AllowHandleDereference::IsAllowed()) return false;
LocalHeap* local_heap = LocalHeap::Current(); if (FLAG_local_heaps) {
if (FLAG_local_heaps && local_heap) { LocalHeap* local_heap = isolate->CurrentLocalHeap();
// Local heap can't access handles when parked // Local heap can't access handles when parked
if (!local_heap->IsHandleDereferenceAllowed()) { if (!local_heap->IsHandleDereferenceAllowed()) {
StdoutStream{} << "Cannot dereference handle owned by " StdoutStream{} << "Cannot dereference handle owned by "
...@@ -55,17 +56,19 @@ bool HandleBase::IsDereferenceAllowed() const { ...@@ -55,17 +56,19 @@ bool HandleBase::IsDereferenceAllowed() const {
return false; return false;
} }
// The current thread owns the handle and thus can dereference it. // We are pretty strict with handle dereferences on background threads: A
return local_heap->ContainsPersistentHandle(location_) || // background local heap is only allowed to dereference its own local or
local_heap->ContainsLocalHandle(location_); // 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 // If LocalHeap::Current() is null, we're on the main thread -- if we were to
// main thread HandleScopes here, we should additionally check the main-thread // check main thread HandleScopes here, we should additionally check the
// LocalHeap. // main-thread LocalHeap.
DCHECK_EQ(ThreadId::Current(), isolate->thread_id()); 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. // TODO(leszeks): Check if the main thread owns this handle.
return true; 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