feat(libSceNKWebKit): implement WTF atom strings #14918

Closed
w4rc0n wants to merge 3 commits from upstream-pr/14918 into main
w4rc0n commented 2026-11-02 01:31:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by w4rc0n on 2026-11-02T01:31:29Z.


What

The WTF::AtomStringImpl and WTF::AtomString exports threw NotImplemented, so guest code stopped as soon as it made an atom string from characters, a literal or a String. Fifteen of them now follow the pinned PS5 WebKit 11.x AtomStringImpl.cpp and AtomString.cpp:

  • AtomStringImpl::add for 8-bit and 16-bit buffers, literals, static strings and substrings; addSlowCase(StringImpl&); lookUp for 8-bit and 16-bit buffers; lookUpSlowCase.
  • AtomString::number for int, unsigned, unsigned long and unsigned long long; fromUTF8Internal; convertToASCIIUppercase.

Each thread has its own table, as with WebKit's per-thread AtomStringTable. Like WebKit's, it holds no references:

  • an atom leaves the table when it is destroyed, through the destroy path from #14917;
  • atoms still alive when their thread exits lose their atom flag.

The table is held through HostThreadLocal, not a plain thread_local, so the MinGW build frees it safely at thread exit (as in e017894bb4).

The cases the source leaves to parts that aren't modelled throw a std::runtime_error and are recorded in docs/dev/debt/libSceNKWebKit.md:

  • addSlowCase(AtomStringTable&, StringImpl&), because the guest table layout is unknown;
  • symbol and external-buffer inputs, because the symbol registry and external-buffer callbacks aren't modelled.

AtomString::number(float) and AtomString::number(double) still call NotImplemented: they need the shortest-form number formatter, which #14259 adds for String::number.

Adapted source. The atom operations adapted from the pinned source are now in their own file, src/WtfAtoms.cpp, under a "Derived from" line and the upstream notice for each pinned source file, verbatim apart from trailing whitespace, the form #13766 uses: the table destructor (AtomStringTable.cpp:28); removal, static atoms, add and the substring-sharing add (AtomStringImpl.cpp :473, :358, :384 and :245); and fromUTF8Internal (AtomString.cpp:120). Independent: the per-thread table, which stays in WtfString.cpp.

tools/pr_overlap.py on this head, with main at 0eba5db30d: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge with main, GitHub's file lists show none of them changing these exports either. #13992, #14172, #14607, #15214, #15241 and #15867 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14917, #14919 and #14920, in the same stack.

Tested

Debian 12, GCC 12.2, Linux 6.18, Release, at the head 129fe3b329162644709464a22d3f1e129f9f1a8b, no local changes:

  • guest_nkwebkit_dates, guest_nkwebkit_numbers, nkwebkit_base, nkwebkit_config, nkwebkit_constants, nkwebkit_fastbitvector, nkwebkit_jsc, nkwebkit_palsessionid, nkwebkit_preferences, nkwebkit_resourceresponse, nkwebkit_webcoregeometry, nkwebkit_wtf, guest_nkwebkit_urls and public_headers pass.
  • The new nkwebkit_wtf cases cover:
    • one atom per content across 8-bit and 16-bit input, with the 24-bit hash in the flags;
    • lookup before an atom is created and after it is destroyed, including removal through the guest StringImpl::destroy;
    • addSlowCase adopting an ordinary string, or returning the existing atom for it;
    • separate tables per thread, and a surviving atom losing its atom flag when its thread exits;
    • static and literal strings whose storage is borrowed and left untouched;
    • substrings, including out-of-range starts;
    • integer bounds for number;
    • valid UTF-8 (Latin-1, an astral character, embedded nulls) and invalid UTF-8 (overlong, surrogate, truncated);
    • convertToASCIIUppercase returning the same atom when the string is already uppercase.
  • tools/progress.py: the 15 exports count as implemented (libSceNKWebKit 1328, against 1313 with only #14917).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41816855710 built feat/nkwebkit-external-strings at its previous head 9d1e021975e6ecbdaf395584d055bc9653d825d2, which contains this PR's commit. It is AnyPS5's Build workflow, dispatched in the author's fork with select=true: the branch merged into main at b11c7bf84f5d2f636ff60166cc3371bd071e24d5, built on windows-latest with WinLibs GCC 15.2 (MinGW-w64, UCRT). All 1390 selected tests passed, none skipped, including the twelve NKWebKit tests, public_headers and patched_libraries. The run started before the fork had a test graph for this main, so it selected more tests than usual. A fork-internal pull request existed only to give the workflow a number. The rebase onto main at 0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4 after #15911 changed only docs/dev/debt/libSceNKWebKit.md, so git range-diff shows the code and tests under test are the same as at that run.

Not built or run: macOS. The Windows run includes the test where a thread creates an atom and exits, so the MinGW thread-exit path ran there. No title or homebrew was run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #14917
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113580154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14918). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T01:31:29Z. --- ### What The `WTF::AtomStringImpl` and `WTF::AtomString` exports threw `NotImplemented`, so guest code stopped as soon as it made an atom string from characters, a literal or a `String`. Fifteen of them now follow the pinned PS5 WebKit 11.x [AtomStringImpl.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/AtomStringImpl.cpp#L182-L533) and [AtomString.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/AtomString.cpp#L83-L125): - `AtomStringImpl::add` for 8-bit and 16-bit buffers, literals, static strings and substrings; `addSlowCase(StringImpl&)`; `lookUp` for 8-bit and 16-bit buffers; `lookUpSlowCase`. - `AtomString::number` for `int`, `unsigned`, `unsigned long` and `unsigned long long`; `fromUTF8Internal`; `convertToASCIIUppercase`. Each thread has its own table, as with WebKit's per-thread `AtomStringTable`. Like WebKit's, it holds no references: - an atom leaves the table when it is destroyed, through the destroy path from #14917; - atoms still alive when their thread exits lose their atom flag. The table is held through `HostThreadLocal`, not a plain `thread_local`, so the MinGW build frees it safely at thread exit (as in e017894bb4). The cases the source leaves to parts that aren't modelled throw a `std::runtime_error` and are recorded in `docs/dev/debt/libSceNKWebKit.md`: - `addSlowCase(AtomStringTable&, StringImpl&)`, because the guest table layout is unknown; - symbol and external-buffer inputs, because the symbol registry and external-buffer callbacks aren't modelled. `AtomString::number(float)` and `AtomString::number(double)` still call `NotImplemented`: they need the shortest-form number formatter, which #14259 adds for `String::number`. **Adapted source.** The atom operations adapted from the pinned source are now in their own file, `src/WtfAtoms.cpp`, under a "Derived from" line and the upstream notice for each pinned source file, verbatim apart from trailing whitespace, the form #13766 uses: the table destructor ([`AtomStringTable.cpp:28`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/AtomStringTable.cpp#L28)); removal, static atoms, `add` and the substring-sharing add ([`AtomStringImpl.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/AtomStringImpl.cpp) `:473`, `:358`, `:384` and `:245`); and `fromUTF8Internal` ([`AtomString.cpp:120`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/AtomString.cpp#L120)). Independent: the per-thread table, which stays in `WtfString.cpp`. `tools/pr_overlap.py` on this head, with `main` at `0eba5db30d`: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge with `main`, GitHub's file lists show none of them changing these exports either. #13992, #14172, #14607, #15214, #15241 and #15867 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14917, #14919 and #14920, in the same stack. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Debian 12, GCC 12.2, Linux 6.18, Release, at the head `129fe3b329162644709464a22d3f1e129f9f1a8b`, no local changes: - `guest_nkwebkit_dates`, `guest_nkwebkit_numbers`, `nkwebkit_base`, `nkwebkit_config`, `nkwebkit_constants`, `nkwebkit_fastbitvector`, `nkwebkit_jsc`, `nkwebkit_palsessionid`, `nkwebkit_preferences`, `nkwebkit_resourceresponse`, `nkwebkit_webcoregeometry`, `nkwebkit_wtf`, `guest_nkwebkit_urls` and `public_headers` pass. - The new `nkwebkit_wtf` cases cover: - one atom per content across 8-bit and 16-bit input, with the 24-bit hash in the flags; - lookup before an atom is created and after it is destroyed, including removal through the guest `StringImpl::destroy`; - `addSlowCase` adopting an ordinary string, or returning the existing atom for it; - separate tables per thread, and a surviving atom losing its atom flag when its thread exits; - static and literal strings whose storage is borrowed and left untouched; - substrings, including out-of-range starts; - integer bounds for `number`; - valid UTF-8 (Latin-1, an astral character, embedded nulls) and invalid UTF-8 (overlong, surrogate, truncated); - `convertToASCIIUppercase` returning the same atom when the string is already uppercase. - `tools/progress.py`: the 15 exports count as implemented (libSceNKWebKit 1328, against 1313 with only #14917). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41816855710](https://github.com/w4rc0n/AnyPS5/actions/runs/41816855710) built `feat/nkwebkit-external-strings` at its previous head `9d1e021975e6ecbdaf395584d055bc9653d825d2`, which contains this PR's commit. It is AnyPS5's `Build` workflow, dispatched in the author's fork with `select=true`: the branch merged into `main` at `b11c7bf84f5d2f636ff60166cc3371bd071e24d5`, built on `windows-latest` with WinLibs GCC 15.2 (MinGW-w64, UCRT). All 1390 selected tests passed, none skipped, including the twelve NKWebKit tests, `public_headers` and `patched_libraries`. The run started before the fork had a test graph for this `main`, so it selected more tests than usual. A fork-internal pull request existed only to give the workflow a number. The rebase onto `main` at `0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4` after #15911 changed only `docs/dev/debt/libSceNKWebKit.md`, so `git range-diff` shows the code and tests under test are the same as at that run. Not built or run: macOS. The Windows run includes the test where a thread creates an atom and exits, so the MinGW thread-exit path ran there. No title or homebrew was run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #14917 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-02 03:55:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T03:55:07Z.

Review: APPROVED


I compared each export with the pinned AtomStringImpl.cpp / AtomString.cpp at 80f77e94 and ran the tests.

What I compared with the source

  • addSlowCase(StringImpl&) returns empty for length 0 and goes the static path when isStatic. Otherwise it inserts the impl itself and sets the atom flag (16), as stringTable().add(&string) + setIsAtom(true) do.
  • add(StringImpl*, start, length):
    • null base gives null;
    • !length || start >= length() gives empty;
    • the length is clamped to length() - start;
    • the whole string goes to add(baseString);
    • otherwise the substring shares the base buffer (SharedSubstring, which keeps the copy-when-short rule of createSubstringSharingImpl).
  • addLiteral and add(StaticStringImpl*) create a non-copying impl over the static data (BufferFromStaticDataTranslator). The test checks that the static impl itself stays untouched.
  • lookUp / lookUpSlowCase find by content and never insert. Empty gives StringImpl::empty() in the slow case.
  • fromUTF8Internal returns null for invalid UTF-8, as the addUTF8 hash returning 0 does. A null end means NUL-terminated. The cases the source only asserts on (null start, end <= start) throw.
  • convertToASCIIUppercase: a null impl gives null, an unchanged string gives itself, otherwise the converted string is interned.
  • number(...) values intern the decimal text, which is what numberToString{Signed,Unsigned}<AtomString> produce.
  • The table key is hashAndFlags >> 8 (the masked 24-bit hash), the same value RemoveAtom uses. The test cross-checks it against concurrentHash.

Tests run (Windows 11, WinLibs GCC 15.2.0, Release; head 4683b72a71 merged onto main 93dbd0f82a)

  • nkwebkit_wtf passes.
  • All 9 nkwebkit* tests pass, including the guest dates and numbers tests. This matters because Release now goes through Destroy for every string.
  • Negative control: with WtfString.cpp, Export.cpp and InventoryExports.hpp from main, the test doesn't build, because these exports are missing there.
  • check_conventions.py --base upstream/main passes.
  • #14917 is an ancestor of this head and is declared in "Depends on".

Non-blocking notes

  1. Symbols in addSlowCase: upstream's addSymbol only interns a SubstringLocation{&base, 0, length}, a substring sharing the symbol's buffer. It never touches the symbol registry. So that path could be implemented later without modelling the registry. Throwing for now is fine, and the debt entry covers it.
  2. An atom whose last reference is dropped on a thread other than the one that interned it makes RemoveAtom throw from inside Release. Upstream only has an ASSERT_WITH_MESSAGE there. Since Release is reached from destructors, that ends in std::terminate rather than a catchable error. Arguably right for a guest bug, but worth knowing if a title trips it.

LGTM.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5731932736 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14918#pullrequestreview-5731932736). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T03:55:07Z. **Review:** APPROVED --- I compared each export with the pinned `AtomStringImpl.cpp` / `AtomString.cpp` at 80f77e94 and ran the tests. **What I compared with the source** - `addSlowCase(StringImpl&)` returns empty for length 0 and goes the static path when `isStatic`. Otherwise it inserts the impl itself and sets the atom flag (16), as `stringTable().add(&string)` + `setIsAtom(true)` do. - `add(StringImpl*, start, length)`: - null base gives null; - `!length || start >= length()` gives empty; - the length is clamped to `length() - start`; - the whole string goes to `add(baseString)`; - otherwise the substring shares the base buffer (`SharedSubstring`, which keeps the copy-when-short rule of `createSubstringSharingImpl`). - `addLiteral` and `add(StaticStringImpl*)` create a non-copying impl over the static data (`BufferFromStaticDataTranslator`). The test checks that the static impl itself stays untouched. - `lookUp` / `lookUpSlowCase` find by content and never insert. Empty gives `StringImpl::empty()` in the slow case. - `fromUTF8Internal` returns null for invalid UTF-8, as the `addUTF8` hash returning 0 does. A null `end` means NUL-terminated. The cases the source only asserts on (null start, `end <= start`) throw. - `convertToASCIIUppercase`: a null impl gives null, an unchanged string gives itself, otherwise the converted string is interned. - `number(...)` values intern the decimal text, which is what `numberToString{Signed,Unsigned}<AtomString>` produce. - The table key is `hashAndFlags >> 8` (the masked 24-bit hash), the same value `RemoveAtom` uses. The test cross-checks it against `concurrentHash`. **Tests run** (Windows 11, WinLibs GCC 15.2.0, Release; head 4683b72a71 merged onto main 93dbd0f82a) - `nkwebkit_wtf` passes. - All 9 `nkwebkit*` tests pass, including the guest dates and numbers tests. This matters because `Release` now goes through `Destroy` for every string. - Negative control: with `WtfString.cpp`, `Export.cpp` and `InventoryExports.hpp` from main, the test doesn't build, because these exports are missing there. - `check_conventions.py --base upstream/main` passes. - #14917 is an ancestor of this head and is declared in "Depends on". **Non-blocking notes** 1. Symbols in `addSlowCase`: upstream's `addSymbol` only interns a `SubstringLocation{&base, 0, length}`, a substring sharing the symbol's buffer. It never touches the symbol registry. So that path could be implemented later without modelling the registry. Throwing for now is fine, and the debt entry covers it. 2. An atom whose last reference is dropped on a thread other than the one that interned it makes `RemoveAtom` throw from inside `Release`. Upstream only has an `ASSERT_WITH_MESSAGE` there. Since `Release` is reached from destructors, that ends in `std::terminate` rather than a catchable error. Arguably right for a guest bug, but worth knowing if a title trips it. LGTM.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14918
No description provided.