[handles] Do not allow handle deref when local heap is parked

When local heap is parked it is not allowed to dereference any handles.
A GC might be relocating objects at that point.

Change-Id: I557682d47f8f0acfe041506833f6b397feb4438b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2289981
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68768}
This commit is contained in:
Dominik Inführ 2020-07-09 20:37:47 +02:00 committed by Commit Bot
parent 8b9c2ac3c6
commit 72bd81c071
3 changed files with 18 additions and 8 deletions

View File

@ -35,20 +35,24 @@ bool HandleBase::IsDereferenceAllowed() const {
HeapObject heap_object = HeapObject::cast(object);
if (IsReadOnlyHeapObject(heap_object)) return true;
if (Heap::InOffThreadSpace(heap_object)) return true;
LocalHeap* local_heap = LocalHeap::Current();
if (V8_UNLIKELY(local_heap)) {
if (local_heap->ContainsPersistentHandle(location_)) {
// The current thread owns the handle and thus can dereference it.
return true;
}
}
Isolate* isolate = GetIsolateFromWritableObject(heap_object);
RootIndex root_index;
if (isolate->roots_table().IsRootHandleLocation(location_, &root_index) &&
RootsTable::IsImmortalImmovable(root_index)) {
return true;
}
LocalHeap* local_heap = LocalHeap::Current();
if (V8_UNLIKELY(local_heap)) {
// Local heap can't access handles when parked
if (!local_heap->IsHandleDereferenceAllowed()) return false;
if (local_heap->ContainsPersistentHandle(location_)) {
// The current thread owns the handle and thus can dereference it.
return true;
}
}
return AllowHandleDereference::IsAllowed();
}
#endif

View File

@ -69,6 +69,11 @@ std::unique_ptr<PersistentHandles> LocalHeap::DetachPersistentHandles() {
bool LocalHeap::ContainsPersistentHandle(Address* location) {
return persistent_handles_ ? persistent_handles_->Contains(location) : false;
}
bool LocalHeap::IsHandleDereferenceAllowed() {
DCHECK_EQ(LocalHeap::Current(), this);
return state_ == ThreadState::Running;
}
#endif
bool LocalHeap::IsParked() {

View File

@ -41,6 +41,7 @@ class V8_EXPORT_PRIVATE LocalHeap {
std::unique_ptr<PersistentHandles> DetachPersistentHandles();
#ifdef DEBUG
bool ContainsPersistentHandle(Address* location);
bool IsHandleDereferenceAllowed();
#endif
bool IsParked();