Commit a3e62593 authored by Nico Hartmann's avatar Nico Hartmann Committed by V8 LUCI CQ

Revert "[test] Migrate cctest/test-global-handles to unittests/"

This reverts commit 3615ae69.

Reason for revert: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20TSAN%20-%20stress-incremental-marking/8836/overview

Original change's description:
> [test] Migrate cctest/test-global-handles to unittests/
>
> Bug: v8:12781
> Change-Id: If7681564f3e0c087e3347557a3f9169625b51607
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3817621
> Reviewed-by: Camillo Bruni <cbruni@chromium.org>
> Commit-Queue: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#82633}

Bug: v8:12781
Change-Id: Ia0e714028e1554b46421d455d86759b61883fd8f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3845712
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Nico Hartmann <nicohartmann@chromium.org>
Owners-Override: Nico Hartmann <nicohartmann@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#82638}
parent c246574a
......@@ -182,6 +182,7 @@ v8_source_set("cctest_sources") {
"test-disasm-regex-helper.h",
"test-field-type-tracking.cc",
"test-func-name-inference.cc",
"test-global-handles.cc",
"test-heap-profiler.cc",
"test-icache.cc",
"test-ignition-statistics-extension.cc",
......
......@@ -522,6 +522,7 @@
'test-bignum-dtoa/*': [SKIP],
'test-cpu-profiler/*': [SKIP],
'test-debug/*': [SKIP],
'test-global-handles/*': [SKIP],
'test-heap-profiler/*': [SKIP],
'test-heap/*': [SKIP],
'test-inobject-slack-tracking/*': [SKIP],
......@@ -976,6 +977,13 @@
'test-embedder-tracing/V8RegisteringEmbedderReference': [SKIP],
'test-external-string-tracker/ExternalString_ExternalBackingStoreSizeIncreasesAfterExternalization': [SKIP],
'test-external-string-tracker/ExternalString_ExternalBackingStoreSizeIncreasesMarkCompact': [SKIP],
'test-global-handles/FinalizerDiesAndKeepsPhantomAliveOnMarkCompact': [SKIP],
'test-global-handles/FinalizerWeakness': [SKIP],
'test-global-handles/GCFromWeakCallbacks': [SKIP],
'test-global-handles/PhantomHandlesWithoutCallbacks': [SKIP],
'test-global-handles/SecondPassPhantomCallbacks': [SKIP],
'test-global-handles/WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact': [SKIP],
'test-global-handles/WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact': [SKIP],
'test-heap-profiler/HeapSnapshotDeleteDuringTakeSnapshot': [SKIP],
'test-heap-profiler/HeapSnapshotObjectsStats': [SKIP],
'test-heap-profiler/SamplingHeapProfilerPretenuredInlineAllocations': [SKIP],
......
......@@ -25,17 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "src/handles/global-handles.h"
#include "include/v8-function.h"
#include "include/v8-locker.h"
#include "src/api/api-inl.h"
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/heap/factory.h"
#include "src/heap/heap-inl.h"
#include "src/objects/objects-inl.h"
#include "test/unittests/heap/heap-utils.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"
namespace v8 {
namespace internal {
......@@ -82,9 +81,12 @@ class NonRootingEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
std::vector<TracedReferenceWrapper*> wrappers_;
};
void InvokeScavenge() { CcTest::CollectGarbage(i::NEW_SPACE); }
void InvokeMarkSweep() { CcTest::CollectAllGarbage(); }
void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Number::New(isolate, 0));
info.GetReturnValue().Set(v8_num(0));
}
struct FlagAndGlobal {
......@@ -152,7 +154,7 @@ void WeakHandleTest(v8::Isolate* isolate, ConstructFunction construct_function,
FlagAndGlobal fp;
construct_function(isolate, context, &fp);
CHECK(IsNewObjectInCorrectGeneration(isolate, fp.handle));
CHECK(heap::InCorrectGeneration(isolate, fp.handle));
fp.handle.SetWeak(&fp, &ResetHandleAndSetFlag,
v8::WeakCallbackType::kParameter);
fp.flag = false;
......@@ -162,44 +164,42 @@ void WeakHandleTest(v8::Isolate* isolate, ConstructFunction construct_function,
CHECK_IMPLIES(survives == SurvivalMode::kDies, fp.flag);
}
void EmptyWeakCallback(const v8::WeakCallbackInfo<void>& data) {}
class GlobalHandlesTest : public TestWithContext {
protected:
template <typename ConstructFunction, typename ModifierFunction>
void TracedReferenceTestWithScavenge(ConstructFunction construct_function,
template <typename ConstructFunction, typename ModifierFunction>
void TracedReferenceTestWithScavenge(v8::Isolate* isolate,
ConstructFunction construct_function,
ModifierFunction modifier_function,
SurvivalMode survives) {
v8::Isolate* isolate = v8_isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
NonRootingEmbedderHeapTracer tracer;
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
auto fp = std::make_unique<TracedReferenceWrapper>();
tracer.Register(fp.get());
construct_function(isolate, context, fp.get());
CHECK(IsNewObjectInCorrectGeneration(isolate, fp->handle));
CHECK(heap::InCorrectGeneration(isolate, fp->handle));
modifier_function(fp.get());
CollectGarbage(i::NEW_SPACE);
InvokeScavenge();
// Scavenge clear properly resets the original handle, so we can check the
// handle directly here.
CHECK_IMPLIES(survives == SurvivalMode::kSurvives, !fp->handle.IsEmpty());
CHECK_IMPLIES(survives == SurvivalMode::kDies, fp->handle.IsEmpty());
}
};
}
void EmptyWeakCallback(const v8::WeakCallbackInfo<void>& data) {}
} // namespace
TEST_F(GlobalHandlesTest, EternalHandles) {
Isolate* isolate = i_isolate();
TEST(EternalHandles) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
EternalHandles* eternal_handles = isolate->eternal_handles();
// Create a number of handles that will not be on a block boundary
const int kArrayLength = 2048 - 1;
const int kArrayLength = 2048-1;
int indices[kArrayLength];
v8::Eternal<v8::Value> eternals[kArrayLength];
......@@ -208,20 +208,19 @@ TEST_F(GlobalHandlesTest, EternalHandles) {
indices[i] = -1;
HandleScope scope(isolate);
v8::Local<v8::Object> object = v8::Object::New(v8_isolate);
object
->Set(v8_isolate->GetCurrentContext(), i,
object->Set(v8_isolate->GetCurrentContext(), i,
v8::Integer::New(v8_isolate, i))
.FromJust();
// Create with internal api
eternal_handles->Create(isolate, *v8::Utils::OpenHandle(*object),
&indices[i]);
eternal_handles->Create(
isolate, *v8::Utils::OpenHandle(*object), &indices[i]);
// Create with external api
CHECK(eternals[i].IsEmpty());
eternals[i].Set(v8_isolate, object);
CHECK(!eternals[i].IsEmpty());
}
CollectAllAvailableGarbage();
CcTest::CollectAllAvailableGarbage();
for (int i = 0; i < kArrayLength; i++) {
for (int j = 0; j < 2; j++) {
......@@ -257,8 +256,10 @@ TEST_F(GlobalHandlesTest, EternalHandles) {
CHECK_EQ(2 * kArrayLength + 1, eternal_handles->handles_count());
}
TEST_F(GlobalHandlesTest, PersistentBaseGetLocal) {
v8::Isolate* isolate = v8_isolate();
TEST(PersistentBaseGetLocal) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Object> o = v8::Object::New(isolate);
......@@ -272,8 +273,9 @@ TEST_F(GlobalHandlesTest, PersistentBaseGetLocal) {
CHECK(v8::Local<v8::Object>::New(isolate, g) == g.Get(isolate));
}
TEST_F(GlobalHandlesTest, WeakPersistentSmi) {
v8::Isolate* isolate = v8_isolate();
TEST(WeakPersistentSmi) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::Number> n = v8::Number::New(isolate, 0);
......@@ -286,8 +288,9 @@ TEST_F(GlobalHandlesTest, WeakPersistentSmi) {
START_ALLOW_USE_DEPRECATED()
TEST_F(GlobalHandlesTest, PhantomHandlesWithoutCallbacks) {
v8::Isolate* isolate = v8_isolate();
TEST(PhantomHandlesWithoutCallbacks) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
v8::Global<v8::Object> g1, g2;
{
......@@ -299,127 +302,129 @@ TEST_F(GlobalHandlesTest, PhantomHandlesWithoutCallbacks) {
}
CHECK(!g1.IsEmpty());
CHECK(!g2.IsEmpty());
CollectAllAvailableGarbage();
CcTest::CollectAllAvailableGarbage();
CHECK(g1.IsEmpty());
CHECK(g2.IsEmpty());
}
END_ALLOW_USE_DEPRECATED()
TEST_F(GlobalHandlesTest, WeakHandleToUnmodifiedJSObjectDiesOnScavenge) {
TEST(WeakHandleToUnmodifiedJSObjectDiesOnScavenge) {
if (FLAG_single_generation) return;
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSObject<FlagAndGlobal>, [](FlagAndGlobal* fp) {},
[this]() { CollectGarbage(i::NEW_SPACE); }, SurvivalMode::kDies);
CcTest::isolate(), &ConstructJSObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeScavenge(); },
SurvivalMode::kDies);
}
TEST_F(GlobalHandlesTest, TracedReferenceToUnmodifiedJSObjectSurvivesScavenge) {
TEST(TracedReferenceToUnmodifiedJSObjectSurvivesScavenge) {
if (FLAG_single_generation) return;
ManualGCScope manual_gc(i_isolate());
ManualGCScope manual_gc;
CcTest::InitializeVM();
TracedReferenceTestWithScavenge(
&ConstructJSObject<TracedReferenceWrapper>,
CcTest::isolate(), &ConstructJSObject<TracedReferenceWrapper>,
[](TracedReferenceWrapper* fp) {}, SurvivalMode::kSurvives);
}
TEST_F(GlobalHandlesTest, WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact) {
TEST(WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact) {
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSObject<FlagAndGlobal>, [](FlagAndGlobal* fp) {},
[this]() { CollectAllGarbage(); }, SurvivalMode::kDies);
CcTest::isolate(), &ConstructJSObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeMarkSweep(); },
SurvivalMode::kDies);
}
TEST_F(GlobalHandlesTest,
WeakHandleToUnmodifiedJSObjectSurvivesMarkCompactWhenInHandle) {
TEST(WeakHandleToUnmodifiedJSObjectSurvivesMarkCompactWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSObject<FlagAndGlobal>,
[this](FlagAndGlobal* fp) {
CcTest::isolate(), &ConstructJSObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(v8_isolate(), fp->handle);
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
},
[this]() { CollectAllGarbage(); }, SurvivalMode::kSurvives);
[]() { InvokeMarkSweep(); }, SurvivalMode::kSurvives);
}
TEST_F(GlobalHandlesTest, WeakHandleToUnmodifiedJSApiObjectDiesOnScavenge) {
TEST(WeakHandleToUnmodifiedJSApiObjectDiesOnScavenge) {
if (FLAG_single_generation) return;
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, [this]() { CollectGarbage(i::NEW_SPACE); },
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeScavenge(); },
SurvivalMode::kDies);
}
TEST_F(GlobalHandlesTest,
TracedReferenceToUnmodifiedJSApiObjectDiesOnScavenge) {
TEST(TracedReferenceToUnmodifiedJSApiObjectDiesOnScavenge) {
if (FLAG_single_generation) return;
ManualGCScope manual_gc(i_isolate());
ManualGCScope manual_gc;
CcTest::InitializeVM();
TracedReferenceTestWithScavenge(
&ConstructJSApiObject<TracedReferenceWrapper>,
CcTest::isolate(), &ConstructJSApiObject<TracedReferenceWrapper>,
[](TracedReferenceWrapper* fp) {}, SurvivalMode::kDies);
}
TEST_F(GlobalHandlesTest,
TracedReferenceToJSApiObjectWithIdentityHashSurvivesScavenge) {
TEST(TracedReferenceToJSApiObjectWithIdentityHashSurvivesScavenge) {
if (FLAG_single_generation) return;
ManualGCScope manual_gc(i_isolate());
Isolate* isolate = i_isolate();
HandleScope scope(isolate);
Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
ManualGCScope manual_gc;
CcTest::InitializeVM();
Isolate* i_isolate = CcTest::i_isolate();
HandleScope scope(i_isolate);
Handle<JSWeakMap> weakmap = i_isolate->factory()->NewJSWeakMap();
TracedReferenceTestWithScavenge(
&ConstructJSApiObject<TracedReferenceWrapper>,
[this, &weakmap, isolate](TracedReferenceWrapper* fp) {
v8::HandleScope scope(v8_isolate());
CcTest::isolate(), &ConstructJSApiObject<TracedReferenceWrapper>,
[&weakmap, i_isolate](TracedReferenceWrapper* fp) {
v8::HandleScope scope(CcTest::isolate());
Handle<JSReceiver> key =
Utils::OpenHandle(*fp->handle.Get(v8_isolate()));
Handle<Smi> smi(Smi::FromInt(23), isolate);
int32_t hash = key->GetOrCreateHash(isolate).value();
Utils::OpenHandle(*fp->handle.Get(CcTest::isolate()));
Handle<Smi> smi(Smi::FromInt(23), i_isolate);
int32_t hash = key->GetOrCreateHash(i_isolate).value();
JSWeakCollection::Set(weakmap, key, smi, hash);
},
SurvivalMode::kSurvives);
}
TEST_F(GlobalHandlesTest,
WeakHandleToUnmodifiedJSApiObjectSurvivesScavengeWhenInHandle) {
TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesScavengeWhenInHandle) {
if (FLAG_single_generation) return;
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[this](FlagAndGlobal* fp) {
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(v8_isolate(), fp->handle);
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
},
[this]() { CollectGarbage(i::NEW_SPACE); }, SurvivalMode::kSurvives);
[]() { InvokeScavenge(); }, SurvivalMode::kSurvives);
}
TEST_F(GlobalHandlesTest, WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact) {
TEST(WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact) {
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, [this]() { CollectAllGarbage(); },
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeMarkSweep(); },
SurvivalMode::kDies);
}
TEST_F(GlobalHandlesTest,
WeakHandleToUnmodifiedJSApiObjectSurvivesMarkCompactWhenInHandle) {
TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesMarkCompactWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
v8_isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[this](FlagAndGlobal* fp) {
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(v8_isolate(), fp->handle);
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
},
[this]() { CollectAllGarbage(); }, SurvivalMode::kSurvives);
[]() { InvokeMarkSweep(); }, SurvivalMode::kSurvives);
}
TEST_F(GlobalHandlesTest,
TracedReferenceToJSApiObjectWithModifiedMapSurvivesScavenge) {
TEST(TracedReferenceToJSApiObjectWithModifiedMapSurvivesScavenge) {
if (FLAG_single_generation) return;
v8::Isolate* isolate = v8_isolate();
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
LocalContext context;
TracedReference<v8::Object> handle;
{
......@@ -429,19 +434,19 @@ TEST_F(GlobalHandlesTest,
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(isolate, "a", v8::Number::New(isolate, 10));
auto function =
function_template->GetFunction(v8_context()).ToLocalChecked();
auto i = function->NewInstance(v8_context()).ToLocalChecked();
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
handle.Reset(isolate, i);
}
CollectGarbage(i::NEW_SPACE);
InvokeScavenge();
CHECK(!handle.IsEmpty());
}
TEST_F(GlobalHandlesTest,
TracedReferenceTOJsApiObjectWithElementsSurvivesScavenge) {
TEST(TracedReferenceTOJsApiObjectWithElementsSurvivesScavenge) {
if (FLAG_single_generation) return;
v8::Isolate* isolate = v8_isolate();
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
LocalContext context;
TracedReference<v8::Object> handle;
{
......@@ -453,11 +458,11 @@ TEST_F(GlobalHandlesTest,
instance_t->Set(isolate, "1", v8::Number::New(isolate, 10));
instance_t->Set(isolate, "2", v8::Number::New(isolate, 10));
auto function =
function_template->GetFunction(v8_context()).ToLocalChecked();
auto i = function->NewInstance(v8_context()).ToLocalChecked();
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
handle.Reset(isolate, i);
}
CollectGarbage(i::NEW_SPACE);
InvokeScavenge();
CHECK(!handle.IsEmpty());
}
......@@ -465,7 +470,7 @@ namespace {
void ForceScavenge2(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
data.GetParameter()->flag = true;
YoungGC(data.GetIsolate());
InvokeScavenge();
}
void ForceScavenge1(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
......@@ -475,7 +480,7 @@ void ForceScavenge1(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void ForceMarkSweep2(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
data.GetParameter()->flag = true;
FullGC(data.GetIsolate());
InvokeMarkSweep();
}
void ForceMarkSweep1(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
......@@ -485,8 +490,9 @@ void ForceMarkSweep1(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
} // namespace
TEST_F(GlobalHandlesTest, GCFromWeakCallbacks) {
v8::Isolate* isolate = v8_isolate();
TEST(GCFromWeakCallbacks) {
v8::Isolate* isolate = CcTest::isolate();
v8::Locker locker(CcTest::isolate());
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
......@@ -494,11 +500,11 @@ TEST_F(GlobalHandlesTest, GCFromWeakCallbacks) {
if (FLAG_single_generation) {
FlagAndGlobal fp;
ConstructJSApiObject(isolate, context, &fp);
CHECK(!InYoungGeneration(isolate, fp.handle));
CHECK(!heap::InYoungGeneration(isolate, fp.handle));
fp.flag = false;
fp.handle.SetWeak(&fp, &ForceMarkSweep1, v8::WeakCallbackType::kParameter);
CollectAllGarbage();
EmptyMessageQueues();
InvokeMarkSweep();
EmptyMessageQueues(isolate);
CHECK(fp.flag);
return;
}
......@@ -508,21 +514,19 @@ TEST_F(GlobalHandlesTest, GCFromWeakCallbacks) {
Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1,
&ForceMarkSweep1};
using GCInvoker = std::function<void(void)>;
GCInvoker invoke_gc[kNumberOfGCTypes] = {
[this]() { CollectGarbage(i::NEW_SPACE); },
[this]() { CollectAllGarbage(); }};
using GCInvoker = void (*)();
GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
FlagAndGlobal fp;
ConstructJSApiObject(isolate, context, &fp);
CHECK(InYoungGeneration(isolate, fp.handle));
CHECK(heap::InYoungGeneration(isolate, fp.handle));
fp.flag = false;
fp.handle.SetWeak(&fp, gc_forcing_callback[inner_gc],
v8::WeakCallbackType::kParameter);
invoke_gc[outer_gc]();
EmptyMessageQueues();
EmptyMessageQueues(isolate);
CHECK(fp.flag);
}
}
......@@ -541,8 +545,9 @@ void FirstPassCallback(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
} // namespace
TEST_F(GlobalHandlesTest, SecondPassPhantomCallbacks) {
v8::Isolate* isolate = v8_isolate();
TEST(SecondPassPhantomCallbacks) {
v8::Isolate* isolate = CcTest::isolate();
v8::Locker locker(CcTest::isolate());
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
......@@ -551,65 +556,72 @@ TEST_F(GlobalHandlesTest, SecondPassPhantomCallbacks) {
fp.flag = false;
fp.handle.SetWeak(&fp, FirstPassCallback, v8::WeakCallbackType::kParameter);
CHECK(!fp.flag);
CollectAllGarbage();
CollectAllGarbage();
InvokeMarkSweep();
InvokeMarkSweep();
CHECK(fp.flag);
}
TEST_F(GlobalHandlesTest, MoveStrongGlobal) {
v8::Isolate* isolate = v8_isolate();
TEST(MoveStrongGlobal) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Global<v8::Object>* global = new Global<v8::Object>();
ConstructJSObject(isolate, global);
CollectAllGarbage();
InvokeMarkSweep();
v8::Global<v8::Object> global2(std::move(*global));
delete global;
CollectAllGarbage();
InvokeMarkSweep();
}
TEST_F(GlobalHandlesTest, MoveWeakGlobal) {
v8::Isolate* isolate = v8_isolate();
TEST(MoveWeakGlobal) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Global<v8::Object>* global = new Global<v8::Object>();
ConstructJSObject(isolate, global);
CollectAllGarbage();
InvokeMarkSweep();
global->SetWeak();
v8::Global<v8::Object> global2(std::move(*global));
delete global;
CollectAllGarbage();
InvokeMarkSweep();
}
TEST_F(GlobalHandlesTest, TotalSizeRegularNode) {
v8::Isolate* isolate = v8_isolate();
TEST(TotalSizeRegularNode) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
v8::HandleScope scope(isolate);
v8::Global<v8::Object>* global = new Global<v8::Object>();
CHECK_EQ(i_isolate()->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate()->global_handles()->UsedSize(), 0);
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
ConstructJSObject(isolate, global);
CHECK_GT(i_isolate()->global_handles()->TotalSize(), 0);
CHECK_GT(i_isolate()->global_handles()->UsedSize(), 0);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_GT(i_isolate->global_handles()->UsedSize(), 0);
delete global;
CHECK_GT(i_isolate()->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate()->global_handles()->UsedSize(), 0);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
}
TEST_F(GlobalHandlesTest, TotalSizeTracedNode) {
v8::Isolate* isolate = v8_isolate();
TEST(TotalSizeTracedNode) {
ManualGCScope manual_gc;
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
v8::HandleScope scope(isolate);
v8::TracedReference<v8::Object>* handle = new TracedReference<v8::Object>();
CHECK_EQ(i_isolate()->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate()->global_handles()->UsedSize(), 0);
CHECK_EQ(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
ConstructJSObject(isolate, handle);
CHECK_GT(i_isolate()->global_handles()->TotalSize(), 0);
CHECK_GT(i_isolate()->global_handles()->UsedSize(), 0);
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_GT(i_isolate->global_handles()->UsedSize(), 0);
delete handle;
CollectAllGarbage();
CHECK_GT(i_isolate()->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate()->global_handles()->UsedSize(), 0);
InvokeMarkSweep();
CHECK_GT(i_isolate->global_handles()->TotalSize(), 0);
CHECK_EQ(i_isolate->global_handles()->UsedSize(), 0);
}
} // namespace internal
......
......@@ -378,7 +378,6 @@ v8_source_set("unittests_sources") {
"heap/embedder-tracing-unittest.cc",
"heap/gc-idle-time-handler-unittest.cc",
"heap/gc-tracer-unittest.cc",
"heap/global-handles-unittest.cc",
"heap/global-safepoint-unittest.cc",
"heap/heap-controller-unittest.cc",
"heap/heap-unittest.cc",
......
......@@ -39,7 +39,9 @@ class ApiWasmTest : public TestWithIsolate {
// value is irrelevant.
Local<Promise> promise =
Local<Promise>::Cast(RunJS("WebAssembly.compileStreaming(null)"));
EmptyMessageQueues();
while (platform::PumpMessageLoop(platform(), isolate())) {
}
CHECK_EQ(expected_state, promise->State());
}
};
......
......@@ -498,6 +498,23 @@ void ConstructJSApiObject(v8::Isolate* isolate, v8::Local<v8::Context> context,
EXPECT_FALSE(global->IsEmpty());
}
namespace {
bool InCorrectGeneration(HeapObject object) {
return FLAG_single_generation ? !i::Heap::InYoungGeneration(object)
: i::Heap::InYoungGeneration(object);
}
template <typename GlobalOrPersistent>
bool InCorrectGeneration(v8::Isolate* isolate,
const GlobalOrPersistent& global) {
v8::HandleScope scope(isolate);
auto tmp = global.Get(isolate);
return InCorrectGeneration(*v8::Utils::OpenHandle(*tmp));
}
} // namespace
enum class SurvivalMode { kSurvives, kDies };
template <typename ModifierFunction, typename ConstructTracedReferenceFunction,
......@@ -515,7 +532,7 @@ void TracedReferenceTest(v8::Isolate* isolate,
const size_t initial_count = global_handles->handles_count();
auto handle = std::make_unique<v8::TracedReference<v8::Object>>();
construct_function(isolate, context, handle.get());
ASSERT_TRUE(IsNewObjectInCorrectGeneration(isolate, *handle));
ASSERT_TRUE(InCorrectGeneration(isolate, *handle));
modifier_function(*handle);
const size_t after_modification_count = global_handles->handles_count();
gc_function();
......@@ -966,8 +983,7 @@ V8_NOINLINE void StackToHeapTest(v8::Isolate* v8_isolate,
v8::HandleScope scope(v8_isolate);
v8::Local<v8::Object> to_object(ConstructTraceableJSApiObject(
v8_isolate->GetCurrentContext(), nullptr, nullptr));
EXPECT_TRUE(
IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
EXPECT_TRUE(InCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
if (!FLAG_single_generation &&
target_handling == TargetHandling::kInitializedOldGen) {
FullGC(v8_isolate);
......@@ -1018,8 +1034,7 @@ V8_NOINLINE void HeapToStackTest(v8::Isolate* v8_isolate,
v8::HandleScope scope(v8_isolate);
v8::Local<v8::Object> to_object(ConstructTraceableJSApiObject(
v8_isolate->GetCurrentContext(), nullptr, nullptr));
EXPECT_TRUE(
IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
EXPECT_TRUE(InCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
if (!FLAG_single_generation &&
target_handling == TargetHandling::kInitializedOldGen) {
FullGC(v8_isolate);
......@@ -1059,8 +1074,7 @@ V8_NOINLINE void StackToStackTest(v8::Isolate* v8_isolate,
v8::HandleScope scope(v8_isolate);
v8::Local<v8::Object> to_object(ConstructTraceableJSApiObject(
v8_isolate->GetCurrentContext(), nullptr, nullptr));
EXPECT_TRUE(
IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
EXPECT_TRUE(InCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
if (!FLAG_single_generation &&
target_handling == TargetHandling::kInitializedOldGen) {
FullGC(v8_isolate);
......
......@@ -220,10 +220,5 @@ std::vector<Handle<FixedArray>> HeapInternalsBase::CreatePadding(
return handles;
}
bool IsNewObjectInCorrectGeneration(HeapObject object) {
return FLAG_single_generation ? !i::Heap::InYoungGeneration(object)
: i::Heap::InYoungGeneration(object);
}
} // namespace internal
} // namespace v8
......@@ -99,22 +99,6 @@ class WithHeapInternals : public TMixin, HeapInternalsBase {
}
};
class V8_NODISCARD TemporaryEmbedderHeapTracerScope {
public:
TemporaryEmbedderHeapTracerScope(v8::Isolate* isolate,
v8::EmbedderHeapTracer* tracer)
: isolate_(isolate) {
isolate_->SetEmbedderHeapTracer(tracer);
}
~TemporaryEmbedderHeapTracerScope() {
isolate_->SetEmbedderHeapTracer(nullptr);
}
private:
v8::Isolate* const isolate_;
};
using TestWithHeapInternals = //
WithHeapInternals< //
WithInternalIsolateMixin< //
......@@ -137,24 +121,6 @@ inline void YoungGC(v8::Isolate* isolate) {
i::NEW_SPACE, i::GarbageCollectionReason::kTesting);
}
template <typename GlobalOrPersistent>
bool InYoungGeneration(v8::Isolate* isolate, const GlobalOrPersistent& global) {
CHECK(!FLAG_single_generation);
v8::HandleScope scope(isolate);
auto tmp = global.Get(isolate);
return i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*tmp));
}
bool IsNewObjectInCorrectGeneration(HeapObject object);
template <typename GlobalOrPersistent>
bool IsNewObjectInCorrectGeneration(v8::Isolate* isolate,
const GlobalOrPersistent& global) {
v8::HandleScope scope(isolate);
auto tmp = global.Get(isolate);
return IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*tmp));
}
} // namespace internal
} // namespace v8
......
......@@ -211,12 +211,6 @@ class WithIsolateScopeMixin : public TMixin {
return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
}
void EmptyMessageQueues() {
while (v8::platform::PumpMessageLoop(internal::V8::GetCurrentPlatform(),
this->v8_isolate())) {
}
}
private:
Local<Value> RunJS(Local<String> source) {
return TryRunJS(source).ToLocalChecked();
......
......@@ -203,13 +203,6 @@
# Performs GC
'APIExceptionTest.ExceptionMessageDoesNotKeepContextAlive': [SKIP],
'GlobalHandlesTest.FinalizerDiesAndKeepsPhantomAliveOnMarkCompact': [SKIP],
'GlobalHandlesTest.FinalizerWeakness': [SKIP],
'GlobalHandlesTest.GCFromWeakCallbacks': [SKIP],
'GlobalHandlesTest.PhantomHandlesWithoutCallbacks': [SKIP],
'GlobalHandlesTest.SecondPassPhantomCallbacks': [SKIP],
'GlobalHandlesTest.WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact': [SKIP],
'GlobalHandlesTest.WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact': [SKIP],
'LocalHeapTest.GCEpilogue': [SKIP],
'UnifiedHeapDetachedTest.AllocationBeforeConfigureHeap': [SKIP],
'UnifiedHeapTest.FindingV8ToBlinkReference': [SKIP],
......@@ -290,7 +283,6 @@
'BignumDtoaTest.*': [SKIP],
'DtoaTest.*': [SKIP],
'DeclsTest.*': [SKIP],
'GlobalHandlesTest.*': [SKIP],
}], # variant == no_wasm_traps
##############################################################################
......
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