Commit bb0f74d3 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[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/+/3283615Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77959}
parent 9151e2bc
...@@ -3534,6 +3534,9 @@ void Heap::FreeLinearAllocationAreas() { ...@@ -3534,6 +3534,9 @@ void Heap::FreeLinearAllocationAreas() {
void Heap::FreeSharedLinearAllocationAreas() { void Heap::FreeSharedLinearAllocationAreas() {
if (!isolate()->shared_isolate()) return; if (!isolate()->shared_isolate()) return;
safepoint()->IterateLocalHeaps([](LocalHeap* local_heap) {
local_heap->FreeSharedLinearAllocationArea();
});
shared_old_allocator_->FreeLinearAllocationArea(); shared_old_allocator_->FreeLinearAllocationArea();
shared_map_allocator_->FreeLinearAllocationArea(); shared_map_allocator_->FreeLinearAllocationArea();
} }
......
...@@ -870,6 +870,7 @@ class Heap { ...@@ -870,6 +870,7 @@ class Heap {
NewSpace* new_space() { return new_space_; } NewSpace* new_space() { return new_space_; }
OldSpace* old_space() { return old_space_; } OldSpace* old_space() { return old_space_; }
OldSpace* shared_old_space() { return shared_old_space_; }
CodeSpace* code_space() { return code_space_; } CodeSpace* code_space() { return code_space_; }
MapSpace* map_space() { return map_space_; } MapSpace* map_space() { return map_space_; }
OldLargeObjectSpace* lo_space() { return lo_space_; } OldLargeObjectSpace* lo_space() { return lo_space_; }
......
...@@ -40,7 +40,8 @@ void LocalFactory::AddToScriptList(Handle<Script> shared) { ...@@ -40,7 +40,8 @@ void LocalFactory::AddToScriptList(Handle<Script> shared) {
HeapObject LocalFactory::AllocateRaw(int size, AllocationType allocation, HeapObject LocalFactory::AllocateRaw(int size, AllocationType allocation,
AllocationAlignment alignment) { AllocationAlignment alignment) {
DCHECK_EQ(allocation, AllocationType::kOld); DCHECK(allocation == AllocationType::kOld ||
allocation == AllocationType::kSharedOld);
return HeapObject::FromAddress(isolate()->heap()->AllocateRawOrFail( return HeapObject::FromAddress(isolate()->heap()->AllocateRawOrFail(
size, allocation, AllocationOrigin::kRuntime, alignment)); size, allocation, AllocationOrigin::kRuntime, alignment));
} }
......
...@@ -54,11 +54,17 @@ AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type, ...@@ -54,11 +54,17 @@ AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type,
return alloc; return alloc;
} }
CHECK_EQ(type, AllocationType::kOld); if (type == AllocationType::kOld) {
if (large_object) if (large_object)
return heap()->lo_space()->AllocateRawBackground(this, size_in_bytes); return heap()->lo_space()->AllocateRawBackground(this, size_in_bytes);
else 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, Address LocalHeap::AllocateRawOrFail(int object_size, AllocationType type,
......
...@@ -108,6 +108,12 @@ void LocalHeap::SetUp() { ...@@ -108,6 +108,12 @@ void LocalHeap::SetUp() {
code_space_allocator_ = code_space_allocator_ =
std::make_unique<ConcurrentAllocator>(this, heap_->code_space()); 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_); DCHECK_NULL(marking_barrier_);
marking_barrier_ = std::make_unique<MarkingBarrier>(this); marking_barrier_ = std::make_unique<MarkingBarrier>(this);
} }
...@@ -249,6 +255,10 @@ void LocalHeap::FreeLinearAllocationArea() { ...@@ -249,6 +255,10 @@ void LocalHeap::FreeLinearAllocationArea() {
code_space_allocator_->FreeLinearAllocationArea(); code_space_allocator_->FreeLinearAllocationArea();
} }
void LocalHeap::FreeSharedLinearAllocationArea() {
shared_old_space_allocator_->FreeLinearAllocationArea();
}
void LocalHeap::MakeLinearAllocationAreaIterable() { void LocalHeap::MakeLinearAllocationAreaIterable() {
old_space_allocator_->MakeLinearAllocationAreaIterable(); old_space_allocator_->MakeLinearAllocationAreaIterable();
code_space_allocator_->MakeLinearAllocationAreaIterable(); code_space_allocator_->MakeLinearAllocationAreaIterable();
......
...@@ -99,6 +99,9 @@ class V8_EXPORT_PRIVATE LocalHeap { ...@@ -99,6 +99,9 @@ class V8_EXPORT_PRIVATE LocalHeap {
ConcurrentAllocator* code_space_allocator() { ConcurrentAllocator* code_space_allocator() {
return code_space_allocator_.get(); return code_space_allocator_.get();
} }
ConcurrentAllocator* shared_old_space_allocator() {
return shared_old_space_allocator_.get();
}
void RegisterCodeObject(Handle<Code> code) { void RegisterCodeObject(Handle<Code> code) {
heap()->RegisterCodeObject(code); heap()->RegisterCodeObject(code);
...@@ -111,6 +114,9 @@ class V8_EXPORT_PRIVATE LocalHeap { ...@@ -111,6 +114,9 @@ class V8_EXPORT_PRIVATE LocalHeap {
// Give up linear allocation areas. Used for mark-compact GC. // Give up linear allocation areas. Used for mark-compact GC.
void FreeLinearAllocationArea(); void FreeLinearAllocationArea();
// Free all shared LABs. Used by the shared mark-compact GC.
void FreeSharedLinearAllocationArea();
// Create filler object in linear allocation areas. Verifying requires // Create filler object in linear allocation areas. Verifying requires
// iterable heap. // iterable heap.
void MakeLinearAllocationAreaIterable(); void MakeLinearAllocationAreaIterable();
...@@ -305,6 +311,7 @@ class V8_EXPORT_PRIVATE LocalHeap { ...@@ -305,6 +311,7 @@ class V8_EXPORT_PRIVATE LocalHeap {
std::unique_ptr<ConcurrentAllocator> old_space_allocator_; std::unique_ptr<ConcurrentAllocator> old_space_allocator_;
std::unique_ptr<ConcurrentAllocator> code_space_allocator_; std::unique_ptr<ConcurrentAllocator> code_space_allocator_;
std::unique_ptr<ConcurrentAllocator> shared_old_space_allocator_;
friend class CollectionBarrier; friend class CollectionBarrier;
friend class ConcurrentAllocator; friend class ConcurrentAllocator;
......
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