Commit ea987074 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/concurrent-descriptor-array-unittest to

... unittests/objects/concurrent-descriptor-array-unittest.

Bug: v8:12781
Change-Id: Iad4e99e256745d2874e6b03c2fe1c91b5599ab30
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3596443Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80091}
parent d86ef6a3
...@@ -199,7 +199,6 @@ v8_source_set("cctest_sources") { ...@@ -199,7 +199,6 @@ v8_source_set("cctest_sources") {
"test-code-layout.cc", "test-code-layout.cc",
"test-code-pages.cc", "test-code-pages.cc",
"test-code-stub-assembler.cc", "test-code-stub-assembler.cc",
"test-concurrent-descriptor-array.cc",
"test-concurrent-feedback-vector.cc", "test-concurrent-feedback-vector.cc",
"test-concurrent-js-array.cc", "test-concurrent-js-array.cc",
"test-concurrent-prototype.cc", "test-concurrent-prototype.cc",
......
...@@ -369,6 +369,7 @@ v8_source_set("unittests_sources") { ...@@ -369,6 +369,7 @@ v8_source_set("unittests_sources") {
"numbers/bigint-unittest.cc", "numbers/bigint-unittest.cc",
"numbers/conversions-unittest.cc", "numbers/conversions-unittest.cc",
"objects/array-list-unittest.cc", "objects/array-list-unittest.cc",
"objects/concurrent-descriptor-array-unittest.cc",
"objects/object-unittest.cc", "objects/object-unittest.cc",
"objects/osr-optimized-code-cache-unittest.cc", "objects/osr-optimized-code-cache-unittest.cc",
"objects/swiss-hash-table-helpers-unittest.cc", "objects/swiss-hash-table-helpers-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 ConcurrentDescriptorArrayTest = TestWithContext;
namespace internal { namespace internal {
static constexpr int kNumHandles = kHandleBlockSize * 2 + kHandleBlockSize / 2; static constexpr int kNumHandles = kHandleBlockSize * 2 + kHandleBlockSize / 2;
...@@ -46,7 +49,7 @@ class ConcurrentSearchThread final : public v8::base::Thread { ...@@ -46,7 +49,7 @@ class ConcurrentSearchThread final : public v8::base::Thread {
for (Handle<JSObject> handle : handles_) { for (Handle<JSObject> handle : handles_) {
// Lookup the named property on the {map}. // Lookup the named property on the {map}.
CHECK(name_->IsUniqueName()); EXPECT_TRUE(name_->IsUniqueName());
Handle<Map> map(handle->map(), &local_heap); Handle<Map> map(handle->map(), &local_heap);
Handle<DescriptorArray> descriptors( Handle<DescriptorArray> descriptors(
...@@ -54,10 +57,10 @@ class ConcurrentSearchThread final : public v8::base::Thread { ...@@ -54,10 +57,10 @@ class ConcurrentSearchThread final : public v8::base::Thread {
bool is_background_thread = true; bool is_background_thread = true;
InternalIndex const number = InternalIndex const number =
descriptors->Search(*name_, *map, is_background_thread); descriptors->Search(*name_, *map, is_background_thread);
CHECK(number.is_found()); EXPECT_TRUE(number.is_found());
} }
CHECK_EQ(handles_.size(), kNumHandles * 2); EXPECT_EQ(static_cast<int>(handles_.size()), kNumHandles * 2);
} }
private: private:
...@@ -69,21 +72,18 @@ class ConcurrentSearchThread final : public v8::base::Thread { ...@@ -69,21 +72,18 @@ 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_F(ConcurrentDescriptorArrayTest, LinearSearchFlatObject) {
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,
...@@ -100,41 +100,38 @@ TEST(LinearSearchFlatObject) { ...@@ -100,41 +100,38 @@ TEST(LinearSearchFlatObject) {
// 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), persistent_name, i_isolate()->heap(), std::move(handles), std::move(ph), persistent_name,
&sema_started)); &sema_started));
CHECK(thread->Start()); EXPECT_TRUE(thread->Start());
sema_started.Wait(); sema_started.Wait();
// Exercise descriptor in main thread too. // Exercise descriptor in main thread too.
for (int i = 0; i < 7; ++i) { for (int i = 0; i < 7; ++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();
} }
CHECK_EQ(js_object->map().NumberOfOwnDescriptors(), 8); EXPECT_EQ(js_object->map().NumberOfOwnDescriptors(), 8);
thread->Join(); thread->Join();
} }
// 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_F(ConcurrentDescriptorArrayTest, LinearSearchFlatObject_ManyElements) {
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,
...@@ -145,13 +142,13 @@ TEST(LinearSearchFlatObject_ManyElements) { ...@@ -145,13 +142,13 @@ TEST(LinearSearchFlatObject_ManyElements) {
// since we are going search in a background thread, we force a linear search // since we are going search in a background thread, we force a linear search
// that is safe to do in the background. // that is safe to do in the background.
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++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();
} }
CHECK_GT(js_object->map().NumberOfOwnDescriptors(), 8); EXPECT_GT(js_object->map().NumberOfOwnDescriptors(), 8);
for (int i = 0; i < kNumHandles; i++) { for (int i = 0; i < kNumHandles; i++) {
handles.push_back(ph->NewHandle(js_object)); handles.push_back(ph->NewHandle(js_object));
...@@ -163,16 +160,16 @@ TEST(LinearSearchFlatObject_ManyElements) { ...@@ -163,16 +160,16 @@ TEST(LinearSearchFlatObject_ManyElements) {
// 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), persistent_name, i_isolate()->heap(), std::move(handles), std::move(ph), persistent_name,
&sema_started)); &sema_started));
CHECK(thread->Start()); EXPECT_TRUE(thread->Start());
sema_started.Wait(); sema_started.Wait();
// Exercise descriptor in main thread too. // Exercise descriptor in main thread too.
for (int i = 10; i < 20; ++i) { for (int i = 10; 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();
......
...@@ -103,6 +103,17 @@ class WithIsolateScopeMixin : public TMixin { ...@@ -103,6 +103,17 @@ class WithIsolateScopeMixin : public TMixin {
return reinterpret_cast<v8::internal::Isolate*>(this->v8_isolate()); return reinterpret_cast<v8::internal::Isolate*>(this->v8_isolate());
} }
i::Handle<i::String> MakeName(const char* str, int suffix) {
v8::base::EmbeddedVector<char, 128> buffer;
v8::base::SNPrintF(buffer, "%s%d", str, suffix);
return MakeString(buffer.begin());
}
i::Handle<i::String> MakeString(const char* str) {
i::Factory* factory = i_isolate()->factory();
return factory->InternalizeUtf8String(str);
}
Local<Value> RunJS(const char* source) { Local<Value> RunJS(const char* source) {
return RunJS( return RunJS(
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked()); v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
......
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