Commit dbf89f8a authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Add --stress-concurrent-allocation flag

Introduce --stress-concurrent-allocation flag. With this flag, V8 will
run periodically start an allocation background task, which allocates
objects. Will be used for testing background allocation.

Bug: v8:10315
Change-Id: Iddb7ff34601a492bc2f26f41cc56a2a899807cfa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2228889Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68172}
parent 3a99db57
......@@ -943,6 +943,10 @@ DEFINE_BOOL(concurrent_array_buffer_sweeping, true,
DEFINE_BOOL(concurrent_allocation, false, "concurrently allocate in old space")
DEFINE_BOOL(local_heaps, false, "allow heap access from background tasks")
DEFINE_NEG_NEG_IMPLICATION(array_buffer_extension, local_heaps)
DEFINE_BOOL(stress_concurrent_allocation, false,
"start background threads that allocate memory")
DEFINE_IMPLICATION(stress_concurrent_allocation, concurrent_allocation)
DEFINE_IMPLICATION(stress_concurrent_allocation, local_heaps)
DEFINE_BOOL(parallel_marking, true, "use parallel marking in atomic pause")
DEFINE_INT(ephemeron_fixpoint_iterations, 10,
"number of fixpoint iterations it takes to switch to linear "
......
......@@ -4,6 +4,8 @@
#include "src/heap/concurrent-allocator.h"
#include "src/execution/isolate.h"
#include "src/handles/persistent-handles.h"
#include "src/heap/concurrent-allocator-inl.h"
#include "src/heap/local-heap.h"
#include "src/heap/marking.h"
......@@ -11,6 +13,42 @@
namespace v8 {
namespace internal {
void StressConcurrentAllocatorTask::RunInternal() {
Heap* heap = isolate_->heap();
LocalHeap local_heap(heap);
ConcurrentAllocator* allocator = local_heap.old_space_allocator();
const int kNumIterations = 2000;
const int kObjectSize = 10 * kTaggedSize;
const int kLargeObjectSize = 8 * KB;
for (int i = 0; i < kNumIterations; i++) {
Address address = allocator->AllocateOrFail(
kObjectSize, AllocationAlignment::kWordAligned,
AllocationOrigin::kRuntime);
heap->CreateFillerObjectAt(address, kObjectSize, ClearRecordedSlots::kNo);
address = allocator->AllocateOrFail(kLargeObjectSize,
AllocationAlignment::kWordAligned,
AllocationOrigin::kRuntime);
heap->CreateFillerObjectAt(address, kLargeObjectSize,
ClearRecordedSlots::kNo);
if (i % 10 == 0) {
local_heap.Safepoint();
}
}
Schedule(isolate_);
}
// static
void StressConcurrentAllocatorTask::Schedule(Isolate* isolate) {
CHECK(FLAG_local_heaps && FLAG_concurrent_allocation);
auto task = std::make_unique<StressConcurrentAllocatorTask>(isolate);
const double kDelayInSeconds = 0.1;
V8::GetCurrentPlatform()->CallDelayedOnWorkerThread(std::move(task),
kDelayInSeconds);
}
Address ConcurrentAllocator::PerformCollectionAndAllocateAgain(
int object_size, AllocationAlignment alignment, AllocationOrigin origin) {
Heap* heap = local_heap_->heap();
......
......@@ -8,12 +8,27 @@
#include "src/common/globals.h"
#include "src/heap/heap.h"
#include "src/heap/spaces.h"
#include "src/tasks/cancelable-task.h"
namespace v8 {
namespace internal {
class LocalHeap;
class StressConcurrentAllocatorTask : public CancelableTask {
public:
explicit StressConcurrentAllocatorTask(Isolate* isolate)
: CancelableTask(isolate), isolate_(isolate) {}
void RunInternal() override;
// Schedules task on background thread
static void Schedule(Isolate* isolate);
private:
Isolate* isolate_;
};
// Concurrent allocator for allocation from background threads/tasks.
// Allocations are served from a TLAB if possible.
class ConcurrentAllocator {
......
......@@ -34,6 +34,7 @@
#include "src/heap/code-object-registry.h"
#include "src/heap/code-stats.h"
#include "src/heap/combined-heap.h"
#include "src/heap/concurrent-allocator.h"
#include "src/heap/concurrent-marking.h"
#include "src/heap/embedder-tracing.h"
#include "src/heap/finalization-registry-cleanup-task.h"
......@@ -5440,6 +5441,10 @@ void Heap::NotifyDeserializationComplete() {
#endif // DEBUG
}
if (FLAG_stress_concurrent_allocation) {
StressConcurrentAllocatorTask::Schedule(isolate());
}
deserialization_complete_ = true;
}
......
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