Skip to content

fix(snapshot): pick a new Set.of and Map.of iteration salt on every start from a boot snapshot, as HotSpot does - #118

Merged
Project516 merged 3 commits into
masterfrom
p516/snapshot-reseed-salt
Dec 3, 2026
Merged

Project516 merged 3 commits into
masterfrom
p516/snapshot-reseed-salt

Conversation

@Project516

Copy link
Copy Markdown
Owner

What this changes

The OpenJDK test java/util/Collection/RandomizedIteration.java failed on #116's CI run ("iteration order not randomized!"). It starts five VMs, each writing the iteration order of a Set.of and a Map.of, and requires the orders to differ. ImmutableCollections picks the salt behind that order from System.nanoTime() in its <clinit>, which HotSpot runs on every start. java-web's boot snapshot froze the salt: only the first two of the five starts booted, and the other three restored the second one's salt. Two samples give the same order about 1.6% of the time with that test's 63 words, so the test failed now and then.

Restoring a snapshot now sets ImmutableCollections.SALT32L and REVERSE the way <clinit> does, from System.nanoTime(). The salt only picks where iteration starts and in which direction; SetN and MapN place and find elements by hashCode() alone, so the sets and maps already in the snapshot stay valid. HotSpot does the same with its archived module graph: its archived sets are iterated with the salt of the current run. nanoTime is now one helper that the native and the restore share.

Tests

  • New test in test/snapshot.test.ts: boot SetOrder twice to take a snapshot, restore it four times (checked by the snapshot file's mtime and inode), and require more than one iteration order of a 20-element Set.of. It passes with the change and fails without it ("one order from every start").
  • test/snapshot.test.ts (8 tests), test/warm-snapshot.test.ts and test/snapshot-depth.test.ts pass. pnpm typecheck passes.
  • This PR's OpenJDK selection includes RandomizedIteration.java, since it changes src/snapshot.ts.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 402a1bd2-2033-4f1e-ab06-12792af6203e
Commits

Reviewing files that changed from the base of the PR and between cf4d1b5 and 98ff89f.

Files selected for processing: 4

  • src/natives/lang.ts
  • src/snapshot.ts
  • test/snapshot.test.ts
  • test/snapshot/SetOrder.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracts System.nanoTime into a shared helper used by both the native and the snapshot restore, and reseeds ImmutableCollections.SALT32L and REVERSE from nanoTime() on every snapshot restore so Set.of and Map.of iteration order varies between starts like HotSpot. Adds a SetOrder test that boots twice to take a snapshot, restores four times, and asserts more than one iteration order appears.


review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exports a shared nanoTime helper from src/natives/lang.ts and wires it into System.nanoTime(). src/snapshot.ts adds reseedImmutableCollections, invoked from restoreVM, which rewrites ImmutableCollections.SALT32L and REVERSE from nanoTime() so each restored start gets a fresh iteration salt as HotSpot does. Adds test/snapshot/SetOrder.java and a snapshot test that boots twice, restores four times, and requires more than one Set.of iteration order.


review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve

@Project516
Project516 enabled auto-merge (squash) December 3, 2026 20:42
@Project516
Project516 disabled auto-merge December 3, 2026 20:43

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR reseeds ImmutableCollections.SALT32L and REVERSE from System.nanoTime() on every snapshot restore, matching HotSpot's per-start iteration salt. It extracts nanoTime as a shared helper used by both the System.nanoTime() native and the restore path, and adds a test that boots SetOrder twice, snapshots, restores four times, and asserts the iteration order changes.


review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve

@Project516
Project516 enabled auto-merge (squash) December 3, 2026 20:48
@Project516
Project516 merged commit 451d6ec into master Dec 3, 2026
16 checks passed
@Project516
Project516 deleted the p516/snapshot-reseed-salt branch December 3, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant