[heap] Support AllocationType::kSharedOld in LocalHeap and LocalFactory

This is in anticipation for sharing internalized and
in-place-internalizable strings across Isolates. When such strings are
shared, background compilation threads need to be able to allocate
strings in the shared old space.

Bug: v8:12007
Change-Id: I93179c9674cc16e5a6125049d20e61495bc1f3a9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3283615
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77959}
This commit is contained in:
Shu-yu Guo 2021-11-16 08:44:07 -08:00 committed by V8 LUCI CQ
parent 9151e2bcc7
commit bb0f74d336
6 changed files with 34 additions and 6 deletions

View File

@ -3534,6 +3534,9 @@ void Heap::FreeLinearAllocationAreas() {
void Heap::FreeSharedLinearAllocationAreas() {
if (!isolate()->shared_isolate()) return;
safepoint()->IterateLocalHeaps([](LocalHeap* local_heap) {
local_heap->FreeSharedLinearAllocationArea();
});
shared_old_allocator_->FreeLinearAllocationArea();
shared_map_allocator_->FreeLinearAllocationArea();
}

View File

@ -870,6 +870,7 @@ class Heap {
NewSpace* new_space() { return new_space_; }
OldSpace* old_space() { return old_space_; }
OldSpace* shared_old_space() { return shared_old_space_; }
CodeSpace* code_space() { return code_space_; }
MapSpace* map_space() { return map_space_; }
OldLargeObjectSpace* lo_space() { return lo_space_; }

View File

@ -40,7 +40,8 @@ void LocalFactory::AddToScriptList(Handle<Script> shared) {
HeapObject LocalFactory::AllocateRaw(int size, AllocationType allocation,
AllocationAlignment alignment) {
DCHECK_EQ(allocation, AllocationType::kOld);
DCHECK(allocation == AllocationType::kOld ||
allocation == AllocationType::kSharedOld);
return HeapObject::FromAddress(isolate()->heap()->AllocateRawOrFail(
size, allocation, AllocationOrigin::kRuntime, alignment));
}

View File

@ -54,11 +54,17 @@ AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type,
return alloc;
}
CHECK_EQ(type, AllocationType::kOld);
if (type == AllocationType::kOld) {
if (large_object)
return heap()->lo_space()->AllocateRawBackground(this, size_in_bytes);
else
return old_space_allocator()->AllocateRaw(size_in_bytes, alignment, origin);
return old_space_allocator()->AllocateRaw(size_in_bytes, alignment,
origin);
}
DCHECK_EQ(type, AllocationType::kSharedOld);
return shared_old_space_allocator()->AllocateRaw(size_in_bytes, alignment,
origin);
}
Address LocalHeap::AllocateRawOrFail(int object_size, AllocationType type,

View File

@ -108,6 +108,12 @@ void LocalHeap::SetUp() {
code_space_allocator_ =
std::make_unique<ConcurrentAllocator>(this, heap_->code_space());
DCHECK_NULL(shared_old_space_allocator_);
if (heap_->isolate()->shared_isolate()) {
shared_old_space_allocator_ =
std::make_unique<ConcurrentAllocator>(this, heap_->shared_old_space());
}
DCHECK_NULL(marking_barrier_);
marking_barrier_ = std::make_unique<MarkingBarrier>(this);
}
@ -249,6 +255,10 @@ void LocalHeap::FreeLinearAllocationArea() {
code_space_allocator_->FreeLinearAllocationArea();
}
void LocalHeap::FreeSharedLinearAllocationArea() {
shared_old_space_allocator_->FreeLinearAllocationArea();
}
void LocalHeap::MakeLinearAllocationAreaIterable() {
old_space_allocator_->MakeLinearAllocationAreaIterable();
code_space_allocator_->MakeLinearAllocationAreaIterable();

View File

@ -99,6 +99,9 @@ class V8_EXPORT_PRIVATE LocalHeap {
ConcurrentAllocator* code_space_allocator() {
return code_space_allocator_.get();
}
ConcurrentAllocator* shared_old_space_allocator() {
return shared_old_space_allocator_.get();
}
void RegisterCodeObject(Handle<Code> code) {
heap()->RegisterCodeObject(code);
@ -111,6 +114,9 @@ class V8_EXPORT_PRIVATE LocalHeap {
// Give up linear allocation areas. Used for mark-compact GC.
void FreeLinearAllocationArea();
// Free all shared LABs. Used by the shared mark-compact GC.
void FreeSharedLinearAllocationArea();
// Create filler object in linear allocation areas. Verifying requires
// iterable heap.
void MakeLinearAllocationAreaIterable();
@ -305,6 +311,7 @@ class V8_EXPORT_PRIVATE LocalHeap {
std::unique_ptr<ConcurrentAllocator> old_space_allocator_;
std::unique_ptr<ConcurrentAllocator> code_space_allocator_;
std::unique_ptr<ConcurrentAllocator> shared_old_space_allocator_;
friend class CollectionBarrier;
friend class ConcurrentAllocator;