Commit 9f0d20b0 authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Support allocation of large shared objects

So far there was no support for allocating large objects in the
shared heap.

Bug: v8:11708
Change-Id: Ie4ec8244fee2e75fc0e2265847fe5976da2645ea
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3811579Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82261}
parent 557a84d6
......@@ -34,6 +34,10 @@ OldLargeObjectSpace* HeapAllocator::lo_space() const {
return static_cast<OldLargeObjectSpace*>(spaces_[LO_SPACE]);
}
OldLargeObjectSpace* HeapAllocator::shared_lo_space() const {
return shared_lo_space_;
}
PagedSpace* HeapAllocator::space_for_maps() const { return space_for_maps_; }
NewSpace* HeapAllocator::new_space() const {
......
......@@ -31,6 +31,7 @@ void HeapAllocator::Setup() {
shared_map_allocator_ = heap_->shared_map_allocator_
? heap_->shared_map_allocator_.get()
: shared_old_allocator_;
shared_lo_space_ = heap_->shared_lo_space();
}
void HeapAllocator::SetReadOnlySpace(ReadOnlySpace* read_only_space) {
......@@ -48,10 +49,12 @@ AllocationResult HeapAllocator::AllocateRawLargeInternal(
return lo_space()->AllocateRaw(size_in_bytes);
case AllocationType::kCode:
return code_lo_space()->AllocateRaw(size_in_bytes);
case AllocationType::kSharedOld:
return shared_lo_space()->AllocateRawBackground(
heap_->main_thread_local_heap(), size_in_bytes);
case AllocationType::kMap:
case AllocationType::kReadOnly:
case AllocationType::kSharedMap:
case AllocationType::kSharedOld:
UNREACHABLE();
}
}
......
......@@ -83,6 +83,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
V8_INLINE NewSpace* new_space() const;
V8_INLINE NewLargeObjectSpace* new_lo_space() const;
V8_INLINE OldLargeObjectSpace* lo_space() const;
V8_INLINE OldLargeObjectSpace* shared_lo_space() const;
V8_INLINE PagedSpace* old_space() const;
V8_INLINE ReadOnlySpace* read_only_space() const;
......@@ -109,6 +110,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
ConcurrentAllocator* shared_old_allocator_;
ConcurrentAllocator* shared_map_allocator_;
OldLargeObjectSpace* shared_lo_space_;
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
// Specifies how many allocations should be performed until returning
......
......@@ -5836,6 +5836,7 @@ void Heap::SetUpSpaces(LinearAllocationArea& new_allocation_info,
Heap* shared_heap = isolate()->shared_isolate()->heap();
shared_old_space_ = shared_heap->old_space();
shared_lo_space_ = shared_heap->lo_space();
shared_old_allocator_.reset(
new ConcurrentAllocator(main_thread_local_heap(), shared_old_space_));
......
......@@ -871,6 +871,7 @@ class Heap {
MapSpace* map_space() { return map_space_; }
inline PagedSpace* space_for_maps();
OldLargeObjectSpace* lo_space() { return lo_space_; }
OldLargeObjectSpace* shared_lo_space() { return shared_lo_space_; }
CodeLargeObjectSpace* code_lo_space() { return code_lo_space_; }
NewLargeObjectSpace* new_lo_space() { return new_lo_space_; }
ReadOnlySpace* read_only_space() { return read_only_space_; }
......@@ -2216,6 +2217,7 @@ class Heap {
ReadOnlySpace* read_only_space_ = nullptr;
OldSpace* shared_old_space_ = nullptr;
OldLargeObjectSpace* shared_lo_space_ = nullptr;
MapSpace* shared_map_space_ = nullptr;
std::unique_ptr<ConcurrentAllocator> shared_old_allocator_;
......
......@@ -63,8 +63,12 @@ AllocationResult LocalHeap::AllocateRaw(int size_in_bytes, AllocationType type,
}
DCHECK_EQ(type, AllocationType::kSharedOld);
return shared_old_space_allocator()->AllocateRaw(size_in_bytes, alignment,
origin);
if (large_object) {
return heap()->code_lo_space()->AllocateRawBackground(this, size_in_bytes);
} else {
return shared_old_space_allocator()->AllocateRaw(size_in_bytes, alignment,
origin);
}
}
Address LocalHeap::AllocateRawOrFail(int object_size, AllocationType type,
......
......@@ -92,6 +92,66 @@ UNINITIALIZED_TEST(ConcurrentAllocationInSharedOldSpace) {
Isolate::Delete(shared_isolate);
}
namespace {
class SharedLargeOldSpaceAllocationThread final : public v8::base::Thread {
public:
explicit SharedLargeOldSpaceAllocationThread(Isolate* shared)
: v8::base::Thread(
base::Thread::Options("SharedOldSpaceAllocationThread")),
shared_(shared) {}
void Run() override {
SetupClientIsolateAndRunCallback(
shared_, [](v8::Isolate* client_isolate, Isolate* i_client_isolate) {
HandleScope scope(i_client_isolate);
const int kNumIterations = 50;
for (int i = 0; i < kNumIterations; i++) {
HandleScope scope(i_client_isolate);
Handle<FixedArray> fixed_array =
i_client_isolate->factory()->NewFixedArray(
kMaxRegularHeapObjectSize / kTaggedSize,
AllocationType::kSharedOld);
CHECK(MemoryChunk::FromHeapObject(*fixed_array)->IsLargePage());
}
CcTest::CollectGarbage(OLD_SPACE, i_client_isolate);
v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(),
client_isolate);
});
}
Isolate* shared_;
};
} // namespace
UNINITIALIZED_TEST(ConcurrentAllocationInSharedLargeOldSpace) {
if (!ReadOnlyHeap::IsReadOnlySpaceShared()) return;
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator(
v8::ArrayBuffer::Allocator::NewDefaultAllocator());
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = allocator.get();
Isolate* shared_isolate = Isolate::NewShared(create_params);
std::vector<std::unique_ptr<SharedLargeOldSpaceAllocationThread>> threads;
const int kThreads = 4;
for (int i = 0; i < kThreads; i++) {
auto thread =
std::make_unique<SharedLargeOldSpaceAllocationThread>(shared_isolate);
CHECK(thread->Start());
threads.push_back(std::move(thread));
}
for (auto& thread : threads) {
thread->Join();
}
Isolate::Delete(shared_isolate);
}
namespace {
class SharedMapSpaceAllocationThread final : public v8::base::Thread {
public:
......
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