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

[test] Tests should only invoke NewSpace::Grow in safepoint

Make sure that tests grow the new space in a safepoint. This fixes
races with concurrent allocation.

Bug: v8:10315
Change-Id: I6fce6740bc3c9385f18bbbcde4b06ba881a03635
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2428946Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70120}
parent d941d31c
......@@ -10,6 +10,7 @@
#include "src/heap/mark-compact.h"
#include "src/heap/memory-allocator.h"
#include "src/heap/paged-spaces.h"
#include "src/heap/safepoint.h"
#include "src/heap/spaces-inl.h"
#include "src/heap/spaces.h"
......@@ -417,6 +418,7 @@ void NewSpace::TearDown() {
void NewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); }
void NewSpace::Grow() {
DCHECK(heap()->safepoint()->IsActive());
// Double the semispace size but only up to maximum capacity.
DCHECK(TotalCapacity() < MaximumCapacity());
size_t new_capacity =
......
......@@ -252,6 +252,18 @@ void EnsureFlagLocalHeapsEnabled() {
if (!FLAG_local_heaps) FLAG_local_heaps = true;
}
void GrowNewSpace(Heap* heap) {
SafepointScope scope(heap);
heap->new_space()->Grow();
}
void GrowNewSpaceToMaximumCapacity(Heap* heap) {
SafepointScope scope(heap);
while (!heap->new_space()->IsAtMaximumCapacity()) {
heap->new_space()->Grow();
}
}
} // namespace heap
} // namespace internal
} // namespace v8
......@@ -72,6 +72,10 @@ void InvokeMarkSweep(Isolate* isolate = nullptr);
void EnsureFlagLocalHeapsEnabled();
void GrowNewSpace(Heap* heap);
void GrowNewSpaceToMaximumCapacity(Heap* heap);
template <typename GlobalOrPersistent>
bool InYoungGeneration(v8::Isolate* isolate, const GlobalOrPersistent& global) {
v8::HandleScope scope(isolate);
......
......@@ -2005,7 +2005,7 @@ TEST(GrowAndShrinkNewSpace) {
// Explicitly growing should double the space capacity.
size_t old_capacity, new_capacity;
old_capacity = new_space->TotalCapacity();
new_space->Grow();
GrowNewSpace(heap);
new_capacity = new_space->TotalCapacity();
CHECK_EQ(2 * old_capacity, new_capacity);
......@@ -2055,7 +2055,7 @@ TEST(CollectingAllAvailableGarbageShrinksNewSpace) {
NewSpace* new_space = heap->new_space();
size_t old_capacity, new_capacity;
old_capacity = new_space->TotalCapacity();
new_space->Grow();
GrowNewSpace(heap);
new_capacity = new_space->TotalCapacity();
CHECK_EQ(2 * old_capacity, new_capacity);
{
......@@ -2485,10 +2485,7 @@ TEST(OptimizedPretenuringAllocationFolding) {
return;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
// Grow new space unitl maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2539,10 +2536,7 @@ TEST(OptimizedPretenuringObjectArrayLiterals) {
}
v8::HandleScope scope(CcTest::isolate());
// Grow new space unitl maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2581,10 +2575,7 @@ TEST(OptimizedPretenuringNestedInObjectProperties) {
}
v8::HandleScope scope(CcTest::isolate());
// Grow new space until maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
// Keep the nested literal alive while its root is freed
i::ScopedVector<char> source(1024);
......@@ -2625,11 +2616,7 @@ TEST(OptimizedPretenuringMixedInObjectProperties) {
return;
v8::HandleScope scope(CcTest::isolate());
// Grow new space unitl maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2684,10 +2671,7 @@ TEST(OptimizedPretenuringDoubleArrayProperties) {
return;
v8::HandleScope scope(CcTest::isolate());
// Grow new space until maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2726,10 +2710,7 @@ TEST(OptimizedPretenuringDoubleArrayLiterals) {
return;
v8::HandleScope scope(CcTest::isolate());
// Grow new space until maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2767,10 +2748,7 @@ TEST(OptimizedPretenuringNestedMixedArrayLiterals) {
return;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
// Grow new space unitl maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2820,10 +2798,7 @@ TEST(OptimizedPretenuringNestedObjectLiterals) {
return;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
// Grow new space unitl maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......@@ -2873,10 +2848,7 @@ TEST(OptimizedPretenuringNestedDoubleLiterals) {
return;
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
// Grow new space unitl maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......
......@@ -139,7 +139,7 @@ UNINITIALIZED_HEAP_TEST(Regress658718) {
v8::Context::New(isolate)->Enter();
Heap* heap = i_isolate->heap();
heap->delay_sweeper_tasks_for_testing_ = true;
heap->new_space()->Grow();
GrowNewSpace(heap);
{
v8::HandleScope inner_handle_scope(isolate);
std::vector<Handle<FixedArray>> handles;
......
......@@ -618,9 +618,7 @@ HEAP_TEST(Regress791582) {
Heap* heap = isolate->heap();
HandleScope scope(isolate);
NewSpace* new_space = heap->new_space();
if (new_space->TotalCapacity() < new_space->MaximumCapacity()) {
new_space->Grow();
}
GrowNewSpace(heap);
int until_page_end = static_cast<int>(new_space->limit() - new_space->top());
......
......@@ -55,6 +55,7 @@ using i::ArrayVector;
using i::SourceLocation;
using i::Vector;
using v8::base::Optional;
using v8::internal::heap::GrowNewSpaceToMaximumCapacity;
namespace {
......@@ -3899,10 +3900,7 @@ TEST(SamplingHeapProfilerPretenuredInlineAllocations) {
// Suppress randomness to avoid flakiness in tests.
v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
// Grow new space until maximum capacity reached.
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
CcTest::heap()->new_space()->Grow();
}
GrowNewSpaceToMaximumCapacity(CcTest::heap());
i::ScopedVector<char> source(1024);
i::SNPrintF(source,
......
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