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