[test] Only update FLAG_local_heaps if disabled

Avoid data race by only setting FLAG_local_heaps to true if not
already enabled.

Bug: v8:10315
Change-Id: Ib562b6d525448f5c088da39bf60928debd97db43
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2426610
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70115}
This commit is contained in:
Dominik Inführ 2020-09-24 12:51:32 +02:00 committed by Commit Bot
parent 5f265c3379
commit d382dab9e5
8 changed files with 29 additions and 15 deletions

View File

@ -246,6 +246,12 @@ bool InCorrectGeneration(HeapObject object) {
: i::Heap::InYoungGeneration(object); : i::Heap::InYoungGeneration(object);
} }
void EnsureFlagLocalHeapsEnabled() {
// Avoid data race in concurrent thread by only setting the flag to true if
// not already enabled.
if (!FLAG_local_heaps) FLAG_local_heaps = true;
}
} // namespace heap } // namespace heap
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8

View File

@ -70,6 +70,8 @@ void InvokeScavenge(Isolate* isolate = nullptr);
void InvokeMarkSweep(Isolate* isolate = nullptr); void InvokeMarkSweep(Isolate* isolate = nullptr);
void EnsureFlagLocalHeapsEnabled();
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);

View File

@ -7206,7 +7206,7 @@ TEST(Regress978156) {
} }
TEST(GarbageCollectionWithLocalHeap) { TEST(GarbageCollectionWithLocalHeap) {
FLAG_local_heaps = true; EnsureFlagLocalHeapsEnabled();
ManualGCScope manual_gc_scope; ManualGCScope manual_gc_scope;
CcTest::InitializeVM(); CcTest::InitializeVM();

View File

@ -70,7 +70,7 @@ class ConcurrentSearchThread final : public v8::base::Thread {
// Uses linear search on a flat object, with up to 8 elements. // Uses linear search on a flat object, with up to 8 elements.
TEST(LinearSearchFlatObject) { TEST(LinearSearchFlatObject) {
FLAG_local_heaps = true; heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
@ -122,8 +122,8 @@ TEST(LinearSearchFlatObject) {
// Uses linear search on a flat object, which has more than 8 elements. // Uses linear search on a flat object, which has more than 8 elements.
TEST(LinearSearchFlatObject_ManyElements) { TEST(LinearSearchFlatObject_ManyElements) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();

View File

@ -68,8 +68,8 @@ class ConcurrentSearchThread final : public v8::base::Thread {
// Test to search on a background thread, while the main thread is idle. // Test to search on a background thread, while the main thread is idle.
TEST(ProtoWalkBackground) { TEST(ProtoWalkBackground) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
@ -108,8 +108,8 @@ TEST(ProtoWalkBackground) {
// Test to search on a background thread, while the main thread modifies the // Test to search on a background thread, while the main thread modifies the
// descriptor array. // descriptor array.
TEST(ProtoWalkBackground_DescriptorArrayWrite) { TEST(ProtoWalkBackground_DescriptorArrayWrite) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
@ -155,8 +155,8 @@ TEST(ProtoWalkBackground_DescriptorArrayWrite) {
} }
TEST(ProtoWalkBackground_PrototypeChainWrite) { TEST(ProtoWalkBackground_PrototypeChainWrite) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();

View File

@ -69,8 +69,8 @@ class LocalHandlesThread final : public v8::base::Thread {
}; };
TEST(CreateLocalHandles) { TEST(CreateLocalHandles) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Address object = kNullAddress; Address object = kNullAddress;
@ -97,8 +97,8 @@ TEST(CreateLocalHandles) {
} }
TEST(CreateLocalHandlesWithoutLocalHandleScope) { TEST(CreateLocalHandlesWithoutLocalHandleScope) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
{ {
@ -108,8 +108,8 @@ TEST(CreateLocalHandlesWithoutLocalHandleScope) {
} }
TEST(DereferenceLocalHandle) { TEST(DereferenceLocalHandle) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
// Create a PersistentHandle to create the LocalHandle, and thus not have a // Create a PersistentHandle to create the LocalHandle, and thus not have a

View File

@ -74,8 +74,8 @@ class PersistentHandlesThread final : public v8::base::Thread {
}; };
TEST(CreatePersistentHandles) { TEST(CreatePersistentHandles) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
@ -110,8 +110,8 @@ TEST(CreatePersistentHandles) {
} }
TEST(DereferencePersistentHandle) { TEST(DereferencePersistentHandle) {
heap::EnsureFlagLocalHeapsEnabled();
CcTest::InitializeVM(); CcTest::InitializeVM();
FLAG_local_heaps = true;
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> phs = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> phs = isolate->NewPersistentHandles();

View File

@ -13,11 +13,17 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
void EnsureFlagLocalHeapsEnabled() {
// Avoid data race in concurrent thread by only setting the flag to true if
// not already enabled.
if (!FLAG_local_heaps) FLAG_local_heaps = true;
}
using SafepointTest = TestWithIsolate; using SafepointTest = TestWithIsolate;
TEST_F(SafepointTest, ReachSafepointWithoutLocalHeaps) { TEST_F(SafepointTest, ReachSafepointWithoutLocalHeaps) {
EnsureFlagLocalHeapsEnabled();
Heap* heap = i_isolate()->heap(); Heap* heap = i_isolate()->heap();
FLAG_local_heaps = true;
bool run = false; bool run = false;
{ {
SafepointScope scope(heap); SafepointScope scope(heap);
@ -47,8 +53,8 @@ class ParkedThread final : public v8::base::Thread {
}; };
TEST_F(SafepointTest, StopParkedThreads) { TEST_F(SafepointTest, StopParkedThreads) {
EnsureFlagLocalHeapsEnabled();
Heap* heap = i_isolate()->heap(); Heap* heap = i_isolate()->heap();
FLAG_local_heaps = true;
int safepoints = 0; int safepoints = 0;
@ -106,8 +112,8 @@ class RunningThread final : public v8::base::Thread {
}; };
TEST_F(SafepointTest, StopRunningThreads) { TEST_F(SafepointTest, StopRunningThreads) {
EnsureFlagLocalHeapsEnabled();
Heap* heap = i_isolate()->heap(); Heap* heap = i_isolate()->heap();
FLAG_local_heaps = true;
const int kThreads = 10; const int kThreads = 10;
const int kRuns = 5; const int kRuns = 5;
@ -139,8 +145,8 @@ TEST_F(SafepointTest, StopRunningThreads) {
} }
TEST_F(SafepointTest, SkipLocalHeapOfThisThread) { TEST_F(SafepointTest, SkipLocalHeapOfThisThread) {
EnsureFlagLocalHeapsEnabled();
Heap* heap = i_isolate()->heap(); Heap* heap = i_isolate()->heap();
FLAG_local_heaps = true;
LocalHeap local_heap(heap); LocalHeap local_heap(heap);
{ {
SafepointScope scope(heap); SafepointScope scope(heap);