v8/test/mjsunit/harmony/weakrefs/stress-finalizationregistry-dirty-enqueue.js
Shu-yu Guo 138ac70f46 [weakrefs] Add test to stress enqueuing of dirty FinalizationRegistries
Bug: v8:8179, chromium:1074621
Change-Id: I26e2e2cef7ae2b1e43526c4cfc2592cc0f6d688f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2169412
Auto-Submit: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67417}
2020-04-28 07:53:52 +00:00

37 lines
1.0 KiB
JavaScript

// Copyright 2020 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.
// Flags: --stress-compaction --expose-gc
// Test that the dirty FinalizationRegistries that are enqueued during GC have
// their slots correctly recorded by the GC.
// 1) Create many JSFinalizationRegistry objects so that they span several pages
// (page size is 256kb).
let registries = [];
for (let i = 0; i < 1024 * 8; i++) {
registries.push(new FinalizationRegistry(() => {}));
}
// 2) Force two GCs to ensure that JSFinalizatonRegistry objects are tenured.
gc();
gc();
// 3) In a function: create a dummy target and register it in all
// JSFinalizatonRegistry objects.
(function() {
let garbage = {};
registries.forEach((fr) => {
fr.register(garbage, 42);
});
garbage = null;
})();
// 4) Outside the function where the target is unreachable: force GC to collect
// the object.
gc();
// 5) Force another GC to test that the slot was correctly updated.
gc();