f6ac5064ba
This is a reland of 1186fc5008
This reland fixes NewSpaceAllocationTopAddress() and
NewSpaceAllocationLimitAddress() by returning nullptr if no new space
is available. This is okay since those are never used later on.
We can't make this a build-time flag because we may only want to disable
the new space for the shared heap.
Original change's description:
> [heap] Disable the young generation in shared heaps
>
> A shared heap will not have a young generation in the beginning.
>
> Bug: v8:11708
> Change-Id: I947ddb91a23a72a8cee3aa3e554723dda8146011
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2891569
> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#74697}
Bug: v8:11708
Change-Id: I254b919f7076ce624d15c924e63cbde5eb4df749
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2912731
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74735}
95 lines
2.9 KiB
C++
95 lines
2.9 KiB
C++
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "include/v8.h"
|
|
#include "src/common/globals.h"
|
|
#include "src/handles/handles-inl.h"
|
|
#include "src/heap/heap.h"
|
|
#include "src/objects/heap-object.h"
|
|
#include "test/cctest/cctest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
namespace {
|
|
const int kNumIterations = 2000;
|
|
|
|
class SharedSpaceAllocationThread final : public v8::base::Thread {
|
|
public:
|
|
explicit SharedSpaceAllocationThread(Isolate* shared)
|
|
: v8::base::Thread(base::Thread::Options("SharedSpaceAllocationThread")),
|
|
shared_(shared) {}
|
|
|
|
void Run() override {
|
|
v8::Isolate::CreateParams create_params;
|
|
allocator_.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
|
|
create_params.array_buffer_allocator = allocator_.get();
|
|
v8::Isolate* client_isolate = v8::Isolate::New(create_params);
|
|
Isolate* i_client_isolate = reinterpret_cast<Isolate*>(client_isolate);
|
|
i_client_isolate->AttachToSharedIsolate(shared_);
|
|
|
|
{
|
|
HandleScope scope(i_client_isolate);
|
|
|
|
for (int i = 0; i < kNumIterations; i++) {
|
|
i_client_isolate->factory()->NewFixedArray(10,
|
|
AllocationType::kSharedOld);
|
|
}
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE, i_client_isolate);
|
|
|
|
v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(),
|
|
client_isolate);
|
|
}
|
|
|
|
client_isolate->Dispose();
|
|
}
|
|
|
|
Isolate* shared_;
|
|
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_;
|
|
};
|
|
} // namespace
|
|
|
|
UNINITIALIZED_TEST(ConcurrentAllocationInSharedOldSpace) {
|
|
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<SharedSpaceAllocationThread>> threads;
|
|
const int kThreads = 4;
|
|
|
|
for (int i = 0; i < kThreads; i++) {
|
|
auto thread = std::make_unique<SharedSpaceAllocationThread>(shared_isolate);
|
|
CHECK(thread->Start());
|
|
threads.push_back(std::move(thread));
|
|
}
|
|
|
|
for (auto& thread : threads) {
|
|
thread->Join();
|
|
}
|
|
|
|
Isolate::Delete(shared_isolate);
|
|
}
|
|
|
|
UNINITIALIZED_TEST(SharedCollection) {
|
|
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);
|
|
|
|
DCHECK_NULL(shared_isolate->heap()->new_space());
|
|
DCHECK_NULL(shared_isolate->heap()->new_lo_space());
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE, shared_isolate);
|
|
Isolate::Delete(shared_isolate);
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|