Skip to content

vm: l1a item factory goes unbalanced compiling ReflectionFactory.newMethod #986

Done

Description

@LSantha

Summary

l1a's ItemFactory still goes out of balance while compiling gnu.java.lang.VMClassHelper#getPackagePortion and sun.reflect.ReflectionFactory#newMethod, so X86BytecodeVisitor.endMethod() logs "Unbalanced item handling" and repairs by calling ifac.balance().

Steps to Reproduce

  1. Java CI: run 45058380234, job 137319309715 (boot32), step "Run QEMU Boot Test (32-bit)"
  2. Or locally: sh build.sh cd-x86-lite, then
    qemu-system-x86_64 -cdrom all/build/cdroms/jnode-x86-lite.iso -m 1024 -M pc -cpu pentium -boot once=d,menu=off -net none -serial file:/tmp/com1.txt -display none
  3. Wait for the serial log to reach System has finished (it does), then:
    grep "Unbalanced item handling" /tmp/com1.txt

Buggy Outcome

Boot succeeds, but two WARN lines appear:

WARN  Unbalanced item handling in gnu.java.lang.VMClassHelper#getPackagePortion!(Ljava/lang/String;)Ljava/lang/String; (leaked 12 item(s))
WARN  Unbalanced item handling in sun.reflect.ReflectionFactory#newMethod!(...(Ljava/lang/reflect/Method; (leaked -12 item(s))

Emitter: core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:675-682, in endMethod(), guarded by ItemFactory.CHECK_BALANCED_ITEM_FACTORY (ItemFactory.java:34, hardcoded true). endMethod() currently repairs with ifac.balance().

Frequency over the last 5 Java CI runs of boot32 (intermittent, not a regression of the commits named):

run head warning
45017224678 92bc62e yes (2 lines)
45025012042 55e824a yes (2 lines)
45020808359 3cc547f no
45054987606 a600fd2 yes (2 lines)
45058380234 3bf9ef5 yes (2 lines)

Note the two numbers: +12 then -12. The item factory is a per-thread reused object across methods, so the second method releases items the first method acquired: an acquire/release pair is not unwound on one of the paths those two methods exercise, and the imbalance only evens out by accident across the pair.

Expected Outcome

The compiler's item accounting is exact, so a clean 32-bit boot emits no "Unbalanced item handling" line at all, and no method has to rely on another method's opposite drift.

Context for why this is still open rather than a duplicate:

Test Coverage Basis

Explicit Constraints

  • Keep ItemFactory.CHECK_BALANCED_ITEM_FACTORY and keep the endMethod() warning. Do not silence this by disabling the check or deleting the warning.
  • Do not "fix" it by calling ifac.balance() earlier, more often, or on more paths. The accounting has to be exact on its own.
  • Java-side only. No changes under core/src/native/x86/, and no config/plugin-list touch.

Environment

  • Commit: 3bf9ef50d (warning also seen on 92bc62e7, 55e824a7, a600fd2e)
  • Host JDK: 8 in Java CI; local host 11 (build needs 1.6/1.7/1.8)
  • Build target: cd-x86-lite
  • Bitness: 32-bit
  • Run: QEMU (command above) / GitHub Actions job 137319309715
  • ISO: all/build/cdroms/jnode-x86-lite.iso
  • Boot reached System has finished: yes

Triage Addendum (auto, 2026-11-23)

  • Area / Kind: area/vm / kind/bug
  • Blast radius: L5 system (l1a/l1b JIT item accounting reaches every L1a-compiled method and the boot path; QEMU boot proof required)
  • Expected scope: core/src/core/org/jnode/vm/x86/compiler/l1a/ItemFactory.java and X86BytecodeVisitor.java (plus l1b emitters if the leak is emission-side), ~20-100 lines, fixing acquire/release symmetry. No-go: CHECK_BALANCED_ITEM_FACTORY, the endMethod() warning, extra ifac.balance() calls, core/src/native/x86/, config/plugin-list files
  • Test path: sh build.sh -f core/build-tests.xml all-junit with a new host test asserting the factory is balanced per compiled method in core/src/test/org/jnode/vm/x86/compiler/l1a/; plus 32-bit sh build.sh cd-x86-lite QEMU boot with zero "Unbalanced item handling" lines
  • Merge signal: human-review (kind/bug on boot-critical JIT accounting)
  • Gaps: none blocking; L1A compiler: investigate 'unbalanced item handling' warnings during boot #618 fixed only the constant-folding pair, so this is a follow-up with a different trigger pair
  • Full report: ## Triage comment below.

✅ Ticket Runner Status

Field Value
Phase DONE
Turn 3/7
Retries 0/3
PR #987
Review in progress no
Started 2026-11-23T18:16:51.686Z

Activity

  1. added
    kind/bug
    area/vm
    on Nov 23, 2026
  2. LSantha commented on Nov 23, 2026

    @LSantha
    OwnerAuthor

    /oc triage issue #986

    Triage run ONLY. Load the jnode-triage-issue skill and obey it. Output is exactly one ## Triage comment plus kind/area label edits. FORBIDDEN in this run: git checkout -b, git push, gh pr create, any branch, any PR.

  3. LSantha commented on Nov 23, 2026

    @LSantha
    OwnerAuthor

    Triage

    • Area: area/vm (org/jnode/vm/x86/compiler/l1a, L1a JIT item accounting)
    • Kind: kind/bug
    • Repro: sh build.sh cd-x86-lite → qemu-system-x86_64 -cdrom all/build/cdroms/jnode-x86-lite.iso -m 1024 -M pc -cpu pentium -boot once=d,menu=off -net none -serial file:/tmp/com1.txt -display none → grep "Unbalanced item handling" /tmp/com1.txt; actual: two WARNs (+12 VMClassHelper#getPackagePortion, -12 sun.reflect.ReflectionFactory#newMethod), expected: none
    • Blast radius: L5 system (l1a/l1b item accounting reaches every L1a-compiled method and the boot path; QEMU boot proof required)
    • Expected scope: core/src/core/org/jnode/vm/x86/compiler/l1a/ItemFactory.java and X86BytecodeVisitor.java (plus l1b emitters if the leak is emission-side), ~20-100 lines fixing acquire/release symmetry. No-go: CHECK_BALANCED_ITEM_FACTORY, the endMethod() warning, extra ifac.balance() calls, core/src/native/x86/, config/plugin-list files
    • Test path: sh build.sh -f core/build-tests.xml all-junit with a new host test asserting the factory is balanced per compiled method in core/src/test/org/jnode/vm/x86/compiler/l1a/; plus 32-bit sh build.sh cd-x86-lite QEMU boot with zero Unbalanced item handling lines
    • Merge signal: human-review (kind/bug on boot-critical JIT accounting)
    • Gaps: none blocking; L1A compiler: investigate 'unbalanced item handling' warnings during boot #618 fixed only the constant-folding pair, so this is a follow-up with a different trigger pair
    • Suggested next: fix
    • Split proposal: none - focused (one accounting defect, two symptom methods)
    • Labels applied: kind/bug, area/vm (already correct; no changes)

    github run

  4. LSantha commented on Nov 23, 2026

    @LSantha
    OwnerAuthor

    /oc Please proceed with this task.

  5. added
    agent/blocked
    on Nov 23, 2026
  6. LSantha commented on Nov 23, 2026

    @LSantha
    OwnerAuthor

    /oc Please proceed with this task.

  7. LSantha commented on Nov 23, 2026

    @LSantha
    OwnerAuthor

    Created PR #987

    github run

  8. added
    agent/done
    and removed
    agent/blocked
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/donearea/vmkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions