Skip to content

fix: reset every field of a pooled frame in JThread.enter again, as a call cut short can leave its frame there dirty - #120

Merged
Project516 merged 2 commits into
masterfrom
p516/fix-pooled-frame-reset
Dec 3, 2026
Merged

Project516 merged 2 commits into
masterfrom
p516/fix-pooled-frame-reset

Conversation

@Project516

@Project516 Project516 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

What this changes

Since #116, java/lang/ScopedValue/StressStackOverflow.java#2 fails on master: an AbstractMethodError for tryClose()Z on an object of the wrong class (ThreadLocalRandom, ScopedValue, the test class), or an internal error Cannot read properties of undefined (reading 'cls') in compiled StressStackOverflow.fibonacci_pad1, where its op parameter arrives as undefined. #116 made JThread.enter write only the method, bytecode, pc and lock of a pooled frame, assuming every frame left in the pool is clean. Under this test's random stack overflows a frame comes back to the pool with its locals spilled (checked with a temporary assertion in enter: such frames appear in ScopedValue.slowGet, ScopedValue.scopedValueCache and ThreadLocalRandom calls, with no JS error before them). The next direct call through that slot then reads the old frame's locals instead of its own arguments. The dirty frames sit at depth 11,999, at the hard stack limit, and are off the stack. A pooled frame spills and its exit runs one instruction in the interpreter (viaInterpreter). That instruction is a call that overflows the stack, so raise unwinds the frame and, as it is direct, throws out of the compiled code. The caller's if(r!==0){t.unpool(cf)...} never runs, and the spilled frame stays in the pool. Resetting in enter covers this, as before #116.

enter resets every field again, as it did before #116. Its time saving was never visible above runner noise.

Tests

… call cut short can leave its frame there dirty
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability during repeated thread execution by ensuring reused execution state is reset before a new run. This helps prevent leftover state from affecting subsequent runs.

JThread.enter now resets reused pooled frames before pushing them. It also sets the direct-call flag during entry instead of during frame creation.

Changes: Pooled Frame Reuse

Layer / File(s) Summary
Reset frame state during entry
src/thread.ts
JThread.enter resets the stack pointer, locals, operand stack, and lock requirement. It sets the direct-call flag before pushing the frame. JThread.pooled no longer sets that flag when creating a frame.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to beee0

This change restores a full reset of reused call frames, which targets the reported intermittent OpenJDK test failures. The change is small, and no concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title describes the main change: JThread.enter again resets every field of a pooled frame, which matches the raw summary (reset of stack pointer, locals, operand stack, lock requirement, direct-ca…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template. It has the sections "What this changes", "Tests", and "Noticed, not fixed". The first section explains the regression from #116, the failing test, the …
Full details: Title check

Explanation

The title describes the main change: JThread.enter again resets every field of a pooled frame, which matches the raw summary (reset of stack pointer, locals, operand stack, lock requirement, direct-call state) and the PR objectives. It is specific and descriptive. The title is long (116 characters, 22 words) and the phrase 'as a call cut short can leave its frame there dirty' adds a causal detail, but the primary change is clear and the title is not misleading.

Full details: Description check

Explanation

The description follows the repository template. It has the sections "What this changes", "Tests", and "Noticed, not fixed". The first section explains the regression from #116, the failing test, the root cause, and the fix. The Tests section lists the CI shard runs, the local runs, and the typecheck result. The "Noticed, not fixed" section is absent. The template says to delete that section when there are no such problems, so its absence is acceptable. The description does not list the behavior changes as a separate list, but the first section describes the behavior change in prose. The description also states that the time saving from #116 was not measurable, which is a performance claim. The template asks for median and spread numbers for performance work. The author gives no numbers for that claim, so the performance evidence is incomplete.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • 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

A rabbit checks the frame anew,
Clears old locals from view,
The stack pointer starts at the start,
The direct-call flag plays its part,
Then pooled frames hop into the queue.

Recent review info

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: e66b9871-b0d4-4f44-afcd-e26664f17825
Commits

Reviewing files that changed from the base of the PR and between 26700c1 and beee088.

Files selected for processing: 1

  • src/thread.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 11

  • GitHub Check: jtreg / run (6)
  • GitHub Check: jtreg / run (5)
  • GitHub Check: jtreg / run (4)
  • GitHub Check: jtreg / run (7)
  • GitHub Check: jtreg / run (3)
  • GitHub Check: jtreg / run (8)
  • GitHub Check: jtreg / run (1)
  • GitHub Check: jtreg / run (2)
  • GitHub Check: test
  • GitHub Check: CodeRabbit
  • GitHub Check: Analyze (java-kotlin)
Additional context used

Learnings: 1

Common learnings

Learnt from: CR
Repo: Project516/java-web

Timestamp: 2026-12-03T20:01:03.255Z
Learning: Source excerpt:
# java-web

## Commands

- Pull requests run the OpenJDK tests in `test/jtreg/passing.txt` that their
  changes need (`scripts/jtreg/select.ts`); releases run all of them. A test
  that fails without a code change is fixed or taken out of `passing.txt`, so
  a green pull request stays green on `master` and at release

@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.

Restores full field reset of pooled frames in JThread.enter: sp, locals, stack, needLock and direct are cleared again on reuse, alongside method, code, pc and lock. This prevents a frame left dirty by a call cut short, such as a JS stack overflow, from leaking spilled state or stale locals into the next direct call at the same pool slot. The direct flag is moved from the pooled factory into enter so every reuse is re-marked direct.


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.

The change restores full field reset of pooled frames in JThread.enter, resetting sp, locals, stack, needLock, and direct in addition to the existing m, code, pc, and lock. This prevents a frame that returned to the pool with spilled locals from being reused with stale data. The direct = true assignment moves from pooled into enter, which is safe because enter unconditionally sets it for every frame it returns.


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

@Project516
Project516 enabled auto-merge (squash) December 3, 2026 20:02
@Project516
Project516 merged commit 4228e9a into master Dec 3, 2026
16 checks passed
@Project516
Project516 deleted the p516/fix-pooled-frame-reset branch December 3, 2026 20:09
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