Commit 9080b8ac authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-concurrent-prototype to unittests

... /objects/concurrent-prototype-unittest.

Bug: v8:12781
Change-Id: Id283af4940a8cff19da78e0404022bc0faf2412e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3599654Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80168}
parent 91453880
...@@ -195,7 +195,6 @@ v8_source_set("cctest_sources") { ...@@ -195,7 +195,6 @@ v8_source_set("cctest_sources") {
"test-atomicops.cc", "test-atomicops.cc",
"test-bignum-dtoa.cc", "test-bignum-dtoa.cc",
"test-code-stub-assembler.cc", "test-code-stub-assembler.cc",
"test-concurrent-prototype.cc",
"test-concurrent-transition-array.cc", "test-concurrent-transition-array.cc",
"test-constantpool.cc", "test-constantpool.cc",
"test-conversions.cc", "test-conversions.cc",
......
...@@ -375,6 +375,7 @@ v8_source_set("unittests_sources") { ...@@ -375,6 +375,7 @@ v8_source_set("unittests_sources") {
"objects/concurrent-descriptor-array-unittest.cc", "objects/concurrent-descriptor-array-unittest.cc",
"objects/concurrent-feedback-vector-unittest.cc", "objects/concurrent-feedback-vector-unittest.cc",
"objects/concurrent-js-array-unittest.cc", "objects/concurrent-js-array-unittest.cc",
"objects/concurrent-prototype-unittest.cc",
"objects/concurrent-script-context-table-unittest.cc", "objects/concurrent-script-context-table-unittest.cc",
"objects/concurrent-string-unittest.cc", "objects/concurrent-string-unittest.cc",
"objects/object-unittest.cc", "objects/object-unittest.cc",
......
// Copyright 2020 the V8 project authors. All rights reserved. // Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -11,10 +11,13 @@ ...@@ -11,10 +11,13 @@
#include "src/heap/local-heap-inl.h" #include "src/heap/local-heap-inl.h"
#include "src/heap/local-heap.h" #include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h" #include "src/heap/parked-scope.h"
#include "test/cctest/cctest.h" #include "test/unittests/test-utils.h"
#include "test/cctest/heap/heap-utils.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using ConcurrentPrototypeTest = TestWithContext;
namespace internal { namespace internal {
static constexpr int kNumHandles = kHandleBlockSize * 2 + kHandleBlockSize / 2; static constexpr int kNumHandles = kHandleBlockSize * 2 + kHandleBlockSize / 2;
...@@ -55,8 +58,7 @@ class ConcurrentSearchThread final : public v8::base::Thread { ...@@ -55,8 +58,7 @@ class ConcurrentSearchThread final : public v8::base::Thread {
map = map_prototype_map; map = map_prototype_map;
} }
} }
CHECK_EQ(static_cast<int>(handles_.size()), kNumHandles * 2);
CHECK_EQ(handles_.size(), kNumHandles * 2);
} }
private: private:
...@@ -67,21 +69,18 @@ class ConcurrentSearchThread final : public v8::base::Thread { ...@@ -67,21 +69,18 @@ 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_F(ConcurrentPrototypeTest, ProtoWalkBackground) {
CcTest::InitializeVM(); std::unique_ptr<PersistentHandles> ph = i_isolate()->NewPersistentHandles();
Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
std::vector<Handle<JSObject>> handles; std::vector<Handle<JSObject>> handles;
auto factory = isolate->factory(); auto factory = i_isolate()->factory();
HandleScope handle_scope(isolate); HandleScope handle_scope(i_isolate());
Handle<JSFunction> function = Handle<JSFunction> function =
factory->NewFunctionForTesting(factory->empty_string()); factory->NewFunctionForTesting(factory->empty_string());
Handle<JSObject> js_object = factory->NewJSObject(function); Handle<JSObject> js_object = factory->NewJSObject(function);
Handle<String> name = CcTest::MakeString("property"); Handle<String> name = MakeString("property");
Handle<Object> value = CcTest::MakeString("dummy_value"); Handle<Object> value = MakeString("dummy_value");
// For the default constructor function no in-object properties are reserved // For the default constructor function no in-object properties are reserved
// hence adding a single property will initialize the property-array. // hence adding a single property will initialize the property-array.
JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, name, value, JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, name, value,
...@@ -96,7 +95,7 @@ TEST(ProtoWalkBackground) { ...@@ -96,7 +95,7 @@ TEST(ProtoWalkBackground) {
// Pass persistent handles to background thread. // Pass persistent handles to background thread.
std::unique_ptr<ConcurrentSearchThread> thread(new ConcurrentSearchThread( std::unique_ptr<ConcurrentSearchThread> thread(new ConcurrentSearchThread(
isolate->heap(), std::move(handles), std::move(ph), &sema_started)); i_isolate()->heap(), std::move(handles), std::move(ph), &sema_started));
CHECK(thread->Start()); CHECK(thread->Start());
sema_started.Wait(); sema_started.Wait();
...@@ -106,21 +105,18 @@ TEST(ProtoWalkBackground) { ...@@ -106,21 +105,18 @@ 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_F(ConcurrentPrototypeTest, ProtoWalkBackground_DescriptorArrayWrite) {
CcTest::InitializeVM(); std::unique_ptr<PersistentHandles> ph = i_isolate()->NewPersistentHandles();
Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
std::vector<Handle<JSObject>> handles; std::vector<Handle<JSObject>> handles;
auto factory = isolate->factory(); auto factory = i_isolate()->factory();
HandleScope handle_scope(isolate); HandleScope handle_scope(i_isolate());
Handle<JSFunction> function = Handle<JSFunction> function =
factory->NewFunctionForTesting(factory->empty_string()); factory->NewFunctionForTesting(factory->empty_string());
Handle<JSObject> js_object = factory->NewJSObject(function); Handle<JSObject> js_object = factory->NewJSObject(function);
Handle<String> name = CcTest::MakeString("property"); Handle<String> name = MakeString("property");
Handle<Object> value = CcTest::MakeString("dummy_value"); Handle<Object> value = MakeString("dummy_value");
// For the default constructor function no in-object properties are reserved // For the default constructor function no in-object properties are reserved
// hence adding a single property will initialize the property-array. // hence adding a single property will initialize the property-array.
JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, name, value, JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, name, value,
...@@ -135,15 +131,15 @@ TEST(ProtoWalkBackground_DescriptorArrayWrite) { ...@@ -135,15 +131,15 @@ TEST(ProtoWalkBackground_DescriptorArrayWrite) {
// Pass persistent handles to background thread. // Pass persistent handles to background thread.
std::unique_ptr<ConcurrentSearchThread> thread(new ConcurrentSearchThread( std::unique_ptr<ConcurrentSearchThread> thread(new ConcurrentSearchThread(
isolate->heap(), std::move(handles), std::move(ph), &sema_started)); i_isolate()->heap(), std::move(handles), std::move(ph), &sema_started));
CHECK(thread->Start()); CHECK(thread->Start());
sema_started.Wait(); sema_started.Wait();
// Exercise descriptor array. // Exercise descriptor array.
for (int i = 0; i < 20; ++i) { for (int i = 0; i < 20; ++i) {
Handle<String> filler_name = CcTest::MakeName("filler_property_", i); Handle<String> filler_name = MakeName("filler_property_", i);
Handle<Object> filler_value = CcTest::MakeString("dummy_value"); Handle<Object> filler_value = MakeString("dummy_value");
JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, filler_name, JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, filler_name,
filler_value, NONE) filler_value, NONE)
.Check(); .Check();
...@@ -152,15 +148,12 @@ TEST(ProtoWalkBackground_DescriptorArrayWrite) { ...@@ -152,15 +148,12 @@ TEST(ProtoWalkBackground_DescriptorArrayWrite) {
thread->Join(); thread->Join();
} }
TEST(ProtoWalkBackground_PrototypeChainWrite) { TEST_F(ConcurrentPrototypeTest, ProtoWalkBackground_PrototypeChainWrite) {
CcTest::InitializeVM(); std::unique_ptr<PersistentHandles> ph = i_isolate()->NewPersistentHandles();
Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
std::vector<Handle<JSObject>> handles; std::vector<Handle<JSObject>> handles;
auto factory = isolate->factory(); auto factory = i_isolate()->factory();
HandleScope handle_scope(isolate); HandleScope handle_scope(i_isolate());
Handle<JSFunction> function = Handle<JSFunction> function =
factory->NewFunctionForTesting(factory->empty_string()); factory->NewFunctionForTesting(factory->empty_string());
...@@ -174,21 +167,21 @@ TEST(ProtoWalkBackground_PrototypeChainWrite) { ...@@ -174,21 +167,21 @@ TEST(ProtoWalkBackground_PrototypeChainWrite) {
// Pass persistent handles to background thread. // Pass persistent handles to background thread.
std::unique_ptr<ConcurrentSearchThread> thread(new ConcurrentSearchThread( std::unique_ptr<ConcurrentSearchThread> thread(new ConcurrentSearchThread(
isolate->heap(), std::move(handles), std::move(ph), &sema_started)); i_isolate()->heap(), std::move(handles), std::move(ph), &sema_started));
CHECK(thread->Start()); CHECK(thread->Start());
// The prototype chain looks like this JSObject -> Object -> null. Change the // The prototype chain looks like this JSObject -> Object -> null. Change the
// prototype of the js_object to be JSObject -> null, and then back a bunch of // prototype of the js_object to be JSObject -> null, and then back a bunch of
// times. // times.
Handle<Map> map(js_object->map(), isolate); Handle<Map> map(js_object->map(), i_isolate());
Handle<HeapObject> old_proto(map->prototype(), isolate); Handle<HeapObject> old_proto(map->prototype(), i_isolate());
DCHECK(!old_proto->IsNull()); DCHECK(!old_proto->IsNull());
Handle<HeapObject> new_proto(old_proto->map().prototype(), isolate); Handle<HeapObject> new_proto(old_proto->map().prototype(), i_isolate());
sema_started.Wait(); sema_started.Wait();
for (int i = 0; i < 20; ++i) { for (int i = 0; i < 20; ++i) {
CHECK(JSReceiver::SetPrototype(isolate, js_object, CHECK(JSReceiver::SetPrototype(i_isolate(), js_object,
i % 2 == 0 ? new_proto : old_proto, false, i % 2 == 0 ? new_proto : old_proto, false,
kDontThrow) kDontThrow)
.FromJust()); .FromJust());
......
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