v8/test/mjsunit/harmony/weakrefs
Nikolaos Papaspyrou 02df9f3ef1 [heap][test] Reland: Fix weakrefs tests for conservative stack scanning
31 out of the 36 JS tests in test/mjsunit/harmony/weakrefs/ rely on
precise GC with the following general pattern: they allocate some
objects, clear all references to them, invoke a GC, then perform
some test that assumes that the GC has reclaimed the objects.
When conservative stack scanning is used, this may fail.

This CL fixes the tests, ensuring that a precise GC will be invoked
when necessary, without scanning the stack. To achieve this, the GC
has to be invoked in asynchronous execution mode, which ensures that
it will be invoked from the event loop without a stack. In some
cases, this change requires a non-trivial change in the tests.

In 5 tests, part of the test's objective was to verify that a weak
reference is not cleared before the end of the turn. In those, it
was not possible to invoke GC asynchronously, as this would
immediately start a new turn. These tests still use synchronous GC
and they have been modified, if necessary, to allow for CSS (i.e.,
to not test that all possible garbage is reclaimed after a
sequential GC). Because of CSS, these tests may not always test
everything that they were intended to.

Some tests are unsuitable for testing in "GC stress" mode, because
this interferes with the execution of FinalizationRegistry cleanup
tasks or with the clearing of WeakRefs, when asynchronous GC is used.

Tests with trivial fix:

- cleanup-from-different-realm
- cleanup
- cleanup-proxy-from-different-realm
- cleanupsome-2
- cleanupsome-after-unregister
- cleanupsome
- finalizationregistry-keeps-holdings-alive
- multiple-dirty-finalization-groups
- stress-finalizationregistry-dirty-enqueue
- undefined-holdings
- unregister-after-cleanup
- unregister-before-cleanup
- unregister-called-twice
- unregister-inside-cleanup2
- unregister-inside-cleanup3
- unregister-inside-cleanup
- unregister-many
- unregister-when-cleanup-already-scheduled
- weak-cell-basics

Tests with non-trivial fixes; same logic but very restructured:

- cleanup-is-not-a-microtask:
- cleanup-on-detached-realm
- finalizationregistry-scheduled-for-cleanup-multiple-times
- finalizationregistry-independent-lifetime
- finalizationregistry-independent-lifetime-multiple
- reentrant-gc-from-cleanup
- symbol-in-finalizationregistry
  (was 2nd part of former symbol-as-weakref-target-gc)
- weak-unregistertoken

Tests with non-trivial fixes; same logic, restructured, using
synchronous GC:

- finalizationregistry-and-weakref
- symbol-as-weakref-target-gc
  (was 1st part of former symbol-as-weakref-target-gc)
- two-weakrefs
- weakref-creation-keeps-alive
- weakref-deref-keeps-alive

This is a reland of commit 20a954f4bc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4191774
> Reviewed-by: Marja Hölttä <marja@chromium.org>
> Reviewed-by: Shu-yu Guo <syg@chromium.org>
> Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#85477}

Bug: v8:13257
Bug: v8:13662
Change-Id: I298ccbc932afc44d5c8c858620a180388a25f5d4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4197675
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85512}
2023-01-27 10:00:33 +00:00
..
basics-cleanupsome.js [weakrefs] Split out FinalizationRegistry#cleanupSome to a different flag 2020-04-09 00:05:07 +00:00
basics.js [symbol-as-weakmap-key] Ship the proposal 2022-11-08 17:47:17 +00:00
cleanup-from-different-realm.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanup-is-not-a-microtask.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanup-on-detached-realm.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanup-proxy-from-different-realm.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanup.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanupsome-2.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanupsome-after-unregister.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
cleanupsome-optional.js [weakrefs] Remove --no-harmony-weak-refs flag 2021-04-08 23:10:53 +00:00
cleanupsome.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
clearkeptobjects-on-quit.js [weakrefs] Remove --no-harmony-weak-refs flag 2021-04-08 23:10:53 +00:00
finalizationregistry-and-weakref.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
finalizationregistry-independent-lifetime-multiple.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
finalizationregistry-independent-lifetime.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
finalizationregistry-keeps-holdings-alive.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
finalizationregistry-scheduled-for-cleanup-multiple-times.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
multiple-dirty-finalization-groups.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
reentrant-gc-from-cleanup.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
stress-finalizationregistry-dirty-enqueue.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
symbol-as-weakref-target-gc.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
symbol-as-weakref-target.js [symbol-as-weakmap-key] Implement Symbol as WeakMap Keys 2022-09-20 07:24:42 +00:00
symbol-in-finalizationregistry.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
two-weakrefs.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
undefined-holdings.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-after-cleanup.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-before-cleanup.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-called-twice.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-inside-cleanup2.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-inside-cleanup3.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-inside-cleanup.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-many.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
unregister-when-cleanup-already-scheduled.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
weak-cell-basics.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
weak-unregistertoken.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
weakref-creation-keeps-alive.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00
weakref-deref-keeps-alive.js [heap][test] Reland: Fix weakrefs tests for conservative stack scanning 2023-01-27 10:00:33 +00:00