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

[test] Move cctest/test-concurrent-script-context-table to unittests

... /objects/concurrent-script-context-table-unittest.

Bug: v8:12781
Change-Id: I6576d5d4cf9c07c189cef9e70e8a6e6f377eb41a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3600551Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80128}
parent 5c362775
...@@ -200,7 +200,6 @@ v8_source_set("cctest_sources") { ...@@ -200,7 +200,6 @@ v8_source_set("cctest_sources") {
"test-code-pages.cc", "test-code-pages.cc",
"test-code-stub-assembler.cc", "test-code-stub-assembler.cc",
"test-concurrent-prototype.cc", "test-concurrent-prototype.cc",
"test-concurrent-script-context-table.cc",
"test-concurrent-transition-array.cc", "test-concurrent-transition-array.cc",
"test-constantpool.cc", "test-constantpool.cc",
"test-conversions.cc", "test-conversions.cc",
......
...@@ -372,6 +372,7 @@ v8_source_set("unittests_sources") { ...@@ -372,6 +372,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-script-context-table-unittest.cc",
"objects/concurrent-string-unittest.cc", "objects/concurrent-string-unittest.cc",
"objects/object-unittest.cc", "objects/object-unittest.cc",
"objects/osr-optimized-code-cache-unittest.cc", "objects/osr-optimized-code-cache-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.h" #include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h" #include "src/heap/parked-scope.h"
#include "src/objects/contexts.h" #include "src/objects/contexts.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 ConcurrentScriptContextTableTest = TestWithContext;
namespace internal { namespace internal {
namespace { namespace {
...@@ -43,7 +46,7 @@ class ScriptContextTableAccessUsedThread final : public v8::base::Thread { ...@@ -43,7 +46,7 @@ class ScriptContextTableAccessUsedThread final : public v8::base::Thread {
for (int i = 0; i < script_context_table_->used(kAcquireLoad); ++i) { for (int i = 0; i < script_context_table_->used(kAcquireLoad); ++i) {
Context context = script_context_table_->get_context(i); Context context = script_context_table_->get_context(i);
CHECK(context.IsScriptContext()); EXPECT_TRUE(context.IsScriptContext());
} }
} }
...@@ -83,7 +86,7 @@ class AccessScriptContextTableThread final : public v8::base::Thread { ...@@ -83,7 +86,7 @@ class AccessScriptContextTableThread final : public v8::base::Thread {
native_context_->synchronized_script_context_table(), &local_heap); native_context_->synchronized_script_context_table(), &local_heap);
Handle<Context> context(script_context_table->get_context(i), Handle<Context> context(script_context_table->get_context(i),
&local_heap); &local_heap);
CHECK(!context.is_null()); EXPECT_TRUE(!context.is_null());
} }
} }
...@@ -94,13 +97,11 @@ class AccessScriptContextTableThread final : public v8::base::Thread { ...@@ -94,13 +97,11 @@ class AccessScriptContextTableThread final : public v8::base::Thread {
Handle<NativeContext> native_context_; Handle<NativeContext> native_context_;
}; };
TEST(ScriptContextTable_Extend) { TEST_F(ConcurrentScriptContextTableTest, ScriptContextTable_Extend) {
CcTest::InitializeVM(); v8::HandleScope scope(isolate());
v8::HandleScope scope(CcTest::isolate());
Isolate* isolate = CcTest::i_isolate();
const bool kIgnoreDuplicateNames = true; const bool kIgnoreDuplicateNames = true;
Factory* factory = isolate->factory(); Factory* factory = i_isolate()->factory();
Handle<NativeContext> native_context = factory->NewNativeContext(); Handle<NativeContext> native_context = factory->NewNativeContext();
Handle<Map> script_context_map = Handle<Map> script_context_map =
factory->NewMap(SCRIPT_CONTEXT_TYPE, kVariableSizeSentinel); factory->NewMap(SCRIPT_CONTEXT_TYPE, kVariableSizeSentinel);
...@@ -111,27 +112,28 @@ TEST(ScriptContextTable_Extend) { ...@@ -111,27 +112,28 @@ TEST(ScriptContextTable_Extend) {
factory->NewScriptContextTable(); factory->NewScriptContextTable();
Handle<ScopeInfo> scope_info = Handle<ScopeInfo> scope_info =
ReadOnlyRoots(isolate).global_this_binding_scope_info_handle(); ReadOnlyRoots(i_isolate()).global_this_binding_scope_info_handle();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
Handle<Context> script_context = Handle<Context> script_context =
factory->NewScriptContext(native_context, scope_info); factory->NewScriptContext(native_context, scope_info);
script_context_table = ScriptContextTable::Extend( script_context_table =
isolate, script_context_table, script_context, kIgnoreDuplicateNames); ScriptContextTable::Extend(i_isolate(), script_context_table,
script_context, kIgnoreDuplicateNames);
} }
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = i_isolate()->NewPersistentHandles();
Handle<ScriptContextTable> persistent_script_context_table = Handle<ScriptContextTable> persistent_script_context_table =
ph->NewHandle(script_context_table); ph->NewHandle(script_context_table);
base::Semaphore sema_started(0); base::Semaphore sema_started(0);
auto thread = std::make_unique<ScriptContextTableAccessUsedThread>( auto thread = std::make_unique<ScriptContextTableAccessUsedThread>(
isolate, isolate->heap(), &sema_started, std::move(ph), i_isolate(), i_isolate()->heap(), &sema_started, std::move(ph),
persistent_script_context_table); persistent_script_context_table);
CHECK(thread->Start()); EXPECT_TRUE(thread->Start());
sema_started.Wait(); sema_started.Wait();
...@@ -139,18 +141,17 @@ TEST(ScriptContextTable_Extend) { ...@@ -139,18 +141,17 @@ TEST(ScriptContextTable_Extend) {
Handle<Context> context = Handle<Context> context =
factory->NewScriptContext(native_context, scope_info); factory->NewScriptContext(native_context, scope_info);
script_context_table = ScriptContextTable::Extend( script_context_table = ScriptContextTable::Extend(
isolate, script_context_table, context, kIgnoreDuplicateNames); i_isolate(), script_context_table, context, kIgnoreDuplicateNames);
} }
thread->Join(); thread->Join();
} }
TEST(ScriptContextTable_AccessScriptContextTable) { TEST_F(ConcurrentScriptContextTableTest,
CcTest::InitializeVM(); ScriptContextTable_AccessScriptContextTable) {
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(isolate());
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory(); Factory* factory = i_isolate()->factory();
Handle<NativeContext> native_context = factory->NewNativeContext(); Handle<NativeContext> native_context = factory->NewNativeContext();
Handle<Map> script_context_map = Handle<Map> script_context_map =
factory->NewMap(SCRIPT_CONTEXT_TYPE, kVariableSizeSentinel); factory->NewMap(SCRIPT_CONTEXT_TYPE, kVariableSizeSentinel);
...@@ -158,29 +159,29 @@ TEST(ScriptContextTable_AccessScriptContextTable) { ...@@ -158,29 +159,29 @@ TEST(ScriptContextTable_AccessScriptContextTable) {
native_context->set_script_context_map(*script_context_map); native_context->set_script_context_map(*script_context_map);
Handle<ScopeInfo> scope_info = Handle<ScopeInfo> scope_info =
ReadOnlyRoots(isolate).global_this_binding_scope_info_handle(); ReadOnlyRoots(i_isolate()).global_this_binding_scope_info_handle();
Handle<ScriptContextTable> script_context_table = Handle<ScriptContextTable> script_context_table =
factory->NewScriptContextTable(); factory->NewScriptContextTable();
Handle<Context> context = Handle<Context> context =
factory->NewScriptContext(native_context, scope_info); factory->NewScriptContext(native_context, scope_info);
script_context_table = script_context_table =
ScriptContextTable::Extend(isolate, script_context_table, context); ScriptContextTable::Extend(i_isolate(), script_context_table, context);
int initialized_entries = 1; int initialized_entries = 1;
g_initialized_entries.store(initialized_entries, std::memory_order_release); g_initialized_entries.store(initialized_entries, std::memory_order_release);
native_context->set_script_context_table(*script_context_table); native_context->set_script_context_table(*script_context_table);
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles(); std::unique_ptr<PersistentHandles> ph = i_isolate()->NewPersistentHandles();
Handle<NativeContext> persistent_native_context = Handle<NativeContext> persistent_native_context =
ph->NewHandle(native_context); ph->NewHandle(native_context);
base::Semaphore sema_started(0); base::Semaphore sema_started(0);
auto thread = std::make_unique<AccessScriptContextTableThread>( auto thread = std::make_unique<AccessScriptContextTableThread>(
isolate, isolate->heap(), &sema_started, std::move(ph), i_isolate(), i_isolate()->heap(), &sema_started, std::move(ph),
persistent_native_context); persistent_native_context);
CHECK(thread->Start()); EXPECT_TRUE(thread->Start());
sema_started.Wait(); sema_started.Wait();
...@@ -189,7 +190,7 @@ TEST(ScriptContextTable_AccessScriptContextTable) { ...@@ -189,7 +190,7 @@ TEST(ScriptContextTable_AccessScriptContextTable) {
Handle<Context> new_context = Handle<Context> new_context =
factory->NewScriptContext(native_context, scope_info); factory->NewScriptContext(native_context, scope_info);
script_context_table = ScriptContextTable::Extend( script_context_table = ScriptContextTable::Extend(
isolate, script_context_table, new_context, kIgnoreDuplicateNames); i_isolate(), script_context_table, new_context, kIgnoreDuplicateNames);
native_context->synchronized_set_script_context_table( native_context->synchronized_set_script_context_table(
*script_context_table); *script_context_table);
// Update with relaxed semantics to not introduce ordering constraints. // Update with relaxed semantics to not introduce ordering constraints.
......
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