feat(libSceNKWebKit): implement WTF::MetaAllocator #21979
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21979"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by RiverWhy on 2026-11-17T00:27:02Z.
What
Implements
WTF::MetaAllocatorandWTF::MetaAllocatorHandle: 13 exports. They are ported from MetaAllocator.cpp andRedBlackTree.hate12a212a531a, the 2021 revision whose WTF ABI the module matches (theMetaAllocator(Lock&, size_t, size_t)constructor and theLocker<Lock>arguments are from that revision). JSC's executable allocator is built onMetaAllocator, and all of these throw onmaintoday.MetaAllocator(10): the base constructor (C2),D2,D0,allocate,release,currentStatistics,addFreshFreeSpace,isInAllocatedMemory,debugFreeSpaceSizeandfreeFreeSpaceNode.allocateNewSpace,notifyNeedPageandnotifyPageIsFreeare called through its vtable. Runs of newly used or freed pages are batched into one call each, as in the source.trackAllocationsgets every handle in its tree, so the guest's inlineMetaAllocatorTracker::findworks.MetaAllocatorHandle(3):D1,D2andshrink. They take the allocator's lock and call itsreleasethrough the vtable. The handle isfastMalloced, because the guest's inlinedereffrees it withfastFree.Layout and ABI, measured on a Linux build of that revision (
sizeof,-fdump-lang-class, theD0disassembly) and checked withstatic_asserts and the test:Lock&at 88 and the tracker at 96.[D1, D0, allocateNewSpace, notifyNeedPage, notifyPageIsFree, release].D0isD1plus a sizedoperator deleteof 104 bytes.allocatereturnsRefPtrthrough a hidden pointer andcurrentStatisticsreturns a 24-byte struct the same way.Differences from the source:
debugFreeSpaceSizesums the free space like a debug build. A release build crashes there.shrinkthrows when asked to grow. A release build would corrupt the free list.MetaAllocatorHandle::dumpstill throws: it needsPrintStream. A contended allocator lock goes toLock::lockSlow, which #21432 implemented onmain.A null object throws.
Debt: a fragment,
docs/dev/debt/changes/feat-nkwebkit-meta-allocator.md, adds the entry under Functional and removes the 13 inventory rows.Overlap:
pr_overlap.pyfinds no open PR with these exports. #18797, #18805, #20327 and #21422 add an include on the same last line oflibSceNKWebKit.hpp, which is a line conflict only.Tested
Linux Mint 22.3:
nkwebkit_wtfmetaallocatortest:addFreshFreeSpace,isInAllocatedMemory, tracker lookups, statistics) over three granules, two page sizes, with and without a tracker. Each transcript of addresses,allocateNewSpacerequests, page notifications and statistics is hashed and compared with the hash from the real 2021MetaAllocator.cpprunning the same driver. As a one-off, 300 sequences of 2,000 operations also matched.isInAllocatedMemorychecked by hand;allocateNewSpacefailing, and zero-size allocations;D0freeing a guest-newed allocator;<=to<in the side choice for a split block fails the transcript check.nkwebkittests built from this branch: 112 passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T00:28:37Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
56d4423fd5:tools/check_conventions.pypassed.nkwebkit_wtfmetaallocator_testsbuilt cleanly.nkwebkit_wtfmetaallocator):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/WtfMetaAllocator.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T02:28:03Z.
Review: COMMENTED
Reviewed — comments
The allocator implementation and ABI have targeted source coverage, but the review bundle excludes two changed files and no checks were run in this session, so approval is not justified.
What I ran
660b35738fb29c4f3a96791035e18d16d115898cusingrepo_read.pytools for the prepared review bundle and targeted repository source.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
Export.cppandinclude/InventoryExports.hppare listed as changed but excluded from the review folder because they are too large. Their full text and surrounding repository behavior were not inspected.nkwebkit_wtfmetaallocatortest, or the broadernkwebkittests. The description reports 112 tests passed and provides an author-reported negative-control result; neither was run here.files.jsonwas not available through the reader; the manifest lists these six included files and the two exclusions above.To get this to a good state
Nothing is required. The author-reported test results are optional context; the excluded files and unrun checks remain unverified.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T18:18:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent allocation metadata failures from leaving allocator state partially updated.
What I ran
f989f42786cd4837c2765d83690ae44cf427f2feusingrepo_read.pyagainst the prepared patch and targeted source ranges.Results
Findings
Blocking
allocateincrements page occupancy andbytesAllocatedbefore allocating the handle withfastMalloc; if that allocation fails or throws, no handle is returned to release the range, while pages remain committed and the allocation is lost from the free-space tree. Allocate the handle before mutating allocator state, or roll back occupancy, bytes, and free-space changes on failure.core/libs/prx/libSceNKWebKit/src/WtfMetaAllocator.cpp:380Non-blocking
None.
Not verified
nkwebkittests; those are author-reported, not checks run here.Export.cppandInventoryExports.hppfull files were excluded as too large; their relevant export hunks were reviewed in the patch. Other unrelated file regions and omitted lockfile or generated build artifacts were not inspected.description.md,commits.md,manifest.json,diff.patch,core/libs/prx/libSceNKWebKit/src/WtfMetaAllocator.cpp,core/libs/prx/libSceNKWebKit/src/WtfMetaAllocatorAbi.hpp,core/libs/prx/libSceNKWebKit/tests/WtfMetaAllocator.cpp,core/libs/prx/libSceNKWebKit/CMakeLists.txt, plus targeted ranges ofExport.cppandInventoryExports.hpp. Files excluded from full-text review:Export.cppandInventoryExports.hpp.To get this to a good state
Allocate or otherwise secure the handle before committing allocator bookkeeping, or add exception-safe rollback for every state change; then rerun the allocator test and relevant
nkwebkittests on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T00:15:41Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the inspected source; the prepared bundle reports extensive reference-transcript tests, but I did not run them.
What I ran
No commands or tests were run. I read the prepared description, commits, manifest, diff, changed implementation, ABI declarations, exports, and test source at head
10f136cdde80a1ec80f3c4e5d55b778a27071ddf. Repository files were read throughrepo_read.py.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
Export.cppandinclude/InventoryExports.hppwere excluded as too large; their manifest entries report no changed new lines. Test execution, build behavior, and console behavior were not verified. The author's reported Linux Mint test results and negative-control result were not run by this review.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T04:03:26Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: retry weak compare/exchange failures before calling the guest lock slow path.
What I ran
Inspected prepared diff and changed source at head
cff897f7389a9ca5804aa369d9ace18e15e8a3b1throughrepo_read.py; no commands or tests were run.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfMetaAllocator.cpp:79:compare_exchange_weakmay fail spuriously while the lock byte remains zero. This branch then callsLock::lockSlowas if the lock were contended; the PR description says that function is currently a stub, so an uncontended allocation or other wrapped operation can throw or fail solely due to a spurious failure. Retry the weak CAS while it reports an available lock, or use a strong compare/exchange.Non-blocking
None.
Not verified
No build, test, or negative control was run. PR description reports Linux Mint tests and 112 passing
nkwebkittests, but these were not independently verified. The full contents ofcore/libs/prx/libSceNKWebKit/Export.cppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppwere excluded by the review folder due to size; targeted ranges and the diff were read. All other changed files listed as included in the manifest were read, including the implementation, ABI header, exports header, test source, integration header, and debt entry. Nofiles.jsonwas available through the reader.To get this to a good state
Retry acquisition after a spurious weak-CAS failure, then rerun the allocator tests and add coverage for the uncontended path with a clear lock byte.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T19:17:45Z.
Review: COMMENTED
Reviewed — comments
The allocator implementation covers the described ABI and allocation paths, but I could not read every file marked for review, so the evidence does not support a formal approval.
What I ran
b3d74728fe18bfedb33fcf575c7085e15cd98cfefrom the prepared diff andrepo_read.py.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The manifest lists 10 changed files. I read the prepared description, commits, diff, and relevant source ranges for
core/libs/prx/libSceNKWebKit/src/WtfMetaAllocator.cpp,core/libs/prx/libSceNKWebKit/src/WtfMetaAllocatorAbi.hpp,core/libs/prx/libSceNKWebKit/include/WtfMetaAllocatorExports.hpp,core/libs/prx/libSceNKWebKit/tests/WtfMetaAllocator.cpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, anddocs/dev/debt/changes/feat-nkwebkit-meta-allocator.md. The relevant changed hunks incore/libs/prx/libSceNKWebKit/Export.cppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppwere checked through the reader, but their full files were not read.core/libs/prx/libSceNKWebKit/include/WtfExports.hppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppwere marked as excluded from the review bundle; the latter's relevant range was read, but its full contents were not. No build, test run, console behavior, or contention behavior was independently confirmed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T03:54:30Z.
Review: COMMENTED
Actionable comments posted: 10
Architecture findings (3)
Advisory architecture findings (3)
8f7ffeb5-dbf8-40aa-86b3-33ff7d3a2367Reviewing files that changed from the base of the PR and between
aecfbf79b1and6b08652ae3.core/libs/prx/libSceNKWebKit/Export.cppcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppcore/libs/prx/libSceNKWebKit/include/WtfMetaAllocatorExports.hppcore/libs/prx/libSceNKWebKit/libSceNKWebKit.hppcore/libs/prx/libSceNKWebKit/src/WtfMetaAllocator.cppcore/libs/prx/libSceNKWebKit/src/WtfMetaAllocatorAbi.hppcore/libs/prx/libSceNKWebKit/tests/WtfMetaAllocator.cppdocs/dev/debt/changes/feat-nkwebkit-meta-allocator.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T03:55:44Z.
Review: APPROVED
Reviewed — looks good
The reviewed change implements the WebKit meta-allocator exports and supporting ABI types; the inspected code supports merging, with one changed file excluded from full-text review.
What I ran
Reviewed head
6b08652ae3018021d9474032b29774e73638125a. No build or test commands were run in this review. The description reports Linux Mint tests, including 112 passingnkwebkittests; those results were not independently run here. The review folder was inspected with the reader, and targeted source context was read throughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceNKWebKit/Export.cppwas excluded from full-text review because it was too large; the removed stub definitions were inspected in the diff. No build, test, Windows, or console behavior was independently verified. The reader did not providereview/files.json; the changed-file inventory was taken fromreview/manifest.json.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:59:29Z.
Review: COMMENTED
Built the branch’s changed sources and ran WtfMetaAllocator on Linux against the existing runtime libraries. The test run passed and covered the allocator lifecycle and allocation cases.
AI-assisted: yes.