// Copyright 2022 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 <optional> #include "src/api/api.h" #include "src/base/platform/semaphore.h" #include "src/handles/handles-inl.h" #include "src/handles/persistent-handles.h" #include "src/heap/heap.h" #include "src/heap/local-heap.h" #include "src/heap/parked-scope.h" #include "src/objects/transitions-inl.h" #include "test/unittests/test-utils.h" #include "testing/gtest/include/gtest/gtest.h" namespace v8 { using ConcurrentTransitionArrayTest = TestWithContext; namespace internal { namespace { // Background search thread class class ConcurrentSearchThread : public v8::base::Thread { … }; // Background search thread class that creates the transitions accessor before // the main thread modifies the TransitionArray, and searches the transition // only after the main thread finished. class ConcurrentSearchOnOutdatedAccessorThread final : public ConcurrentSearchThread { … }; // Search on the main thread and in the background thread at the same time. TEST_F(ConcurrentTransitionArrayTest, FullFieldTransitions_OnlySearch) { … } // Search and insert on the main thread, while the background thread searches at // the same time. TEST_F(ConcurrentTransitionArrayTest, FullFieldTransitions) { … } // Search and insert on the main thread which changes the encoding from kWeakRef // to kFullTransitionArray, while the background thread searches at the same // time. TEST_F(ConcurrentTransitionArrayTest, WeakRefToFullFieldTransitions) { … } // Search and insert on the main thread, while the background thread searches at // the same time. In this case, we have a kFullTransitionArray with enough slack // when we are concurrently writing. TEST_F(ConcurrentTransitionArrayTest, FullFieldTransitions_withSlack) { … } // Search and insert on the main thread which changes the encoding from // kUninitialized to kFullTransitionArray, while the background thread searches // at the same time. TEST_F(ConcurrentTransitionArrayTest, UninitializedToFullFieldTransitions) { … } // In this test the background search will hold a pointer to an old transition // array with no slack, while the main thread will try to insert a value into // it. This makes it so that the main thread will create a new array, and the // background thread will have a pointer to the old one. TEST_F(ConcurrentTransitionArrayTest, FullFieldTransitions_BackgroundSearchOldPointer) { … } } // anonymous namespace } // namespace internal } // namespace v8