Skip to content

All three JNode compilers (l1a, l1b, l2) PASS astore_2 spec compliance.#547

Open
opencode-agent[bot] wants to merge 1 commit into
masterfrom
opencode/issue218-20260620205733
Open

All three JNode compilers (l1a, l1b, l2) PASS astore_2 spec compliance.#547
opencode-agent[bot] wants to merge 1 commit into
masterfrom
opencode/issue218-20260620205733

Conversation

@opencode-agent

Copy link
Copy Markdown

Spec compliance report

Compiler Status Issues
l1a ✅ PASS None
l1b ✅ PASS None
l2 ✅ PASS None

Details

l1a Implementation

  • Status: ✅ PASS
  • Files: core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:1297, core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:4375 (wstore), core/src/core/org/jnode/vm/x86/compiler/l1a/X86StackFrame.java:322 (getEbpOffset), core/src/core/org/jnode/vm/bytecode/BytecodeParser.java:422 (parser dispatch)
  • Issues: None

Analysis:

  • BytecodeParser correctly decodes opcode 0x4D (astore_2) at line 422, calling handler.visit_astore(2) with implicit index 2.
  • X86BytecodeVisitor.visit_astore (line 1297) delegates to wstore(JvmType.REFERENCE, index).
  • wstore (line 4375) correctly handles category-1 reference values: pops WordItem from virtual stack, pins aliases via vstack.loadLocal, computes frame offset via stackFrame.getEbpOffset, emits MOV to [EBP+disp].
  • X86StackFrame.getEbpOffset (line 322) correctly calculates local offsets: for index >= argSlotCount, offset = (index - argSlotCount + 1) * -slotSize.
  • Wide prefix (0xC4) correctly handled at parser lines 827-872: reads 16-bit index for astore (0x3A); not applicable to astore_2 which has implicit index.
  • Stack effect: pops 1 category-1 item (REFERENCE), matching JVM spec "..., objectref → ...".

l1b Implementation

  • Status: ✅ PASS
  • Files: core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:1471, core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:5368 (wstore), core/src/core/org/jnode/vm/x86/compiler/l1b/X86StackFrame.java:314 (getEbpOffset), core/src/core/org/jnode/vm/bytecode/BytecodeParser.java:422 (parser dispatch)
  • Issues: None

Analysis:

  • Identical parser dispatch as l1a (shared BytecodeParser).
  • visit_astore (line 1471) delegates to wstore(JvmType.REFERENCE, index).
  • wstore (line 5368) similar logic: pops WordItem, handles constant tracking via constLocals, pins aliases, computes offset, emits MOV to [EBP+disp].
  • X86StackFrame.getEbpOffset (line 314) identical offset calculation.
  • Stack effect and type handling identical to l1a, spec-compliant.

l2 Implementation

  • Status: ✅ PASS
  • Files: core/src/core/org/jnode/vm/compiler/ir/IRGenerator.java:415 (visit_astore), core/src/core/org/jnode/vm/x86/compiler/l2/GenericX86CodeGenerator.java:278 (generateCodeFor VariableRefAssignQuad), core/src/core/org/jnode/vm/x86/compiler/l2/X86StackFrame.java:322 (getEbpOffset), core/src/core/org/jnode/vm/x86/compiler/l2/L2ByteCodeSupportChecker.java (no override = supported)
  • Issues: None

Analysis:

  • IRGenerator.visit_astore (line 415): stackOffset -= 1, sets Operand.REFERENCE for local[index] and stack[stackOffset], emits VariableRefAssignQuad(index, stackOffset).
  • GenericX86CodeGenerator.generateCodeFor(VariableRefAssignQuad) (line 278) handles STACK→STACK, REGISTER→STACK, CONSTANT→STACK, TOPS→STACK for LHS=STACK (local), emitting MOV/POP to [EBP+disp].
  • X86StackFrame.getEbpOffset (line 322) identical offset calculation.
  • L2ByteCodeSupportChecker does NOT override visit_astore → instruction supported.
  • Wide prefix: IRGenerator.visit_astore(int index) accepts any index; parser handles wide by calling with 16-bit index.
  • Stack effect: pops 1 category-1 item (Operand.REFERENCE = 1 slot), matching spec.
  • Note: returnAddress type (for jsr/ret) not modeled; L2ByteCodeSupportChecker marks jsr/ret as unsupported — known L2 limitation, not an astore_2 issue.

JVM Spec References (astore_2)

Spec Page: https://docs.oracle.com/javase/specs/jvms/se6/html/Instructions2.doc.html

  • Opcode: 0x4D (77)
  • Format: astore_2
  • Operand Stack: ..., objectref → ...
  • Description: Index 2 into local variable array. objectref (type returnAddress or reference) popped and stored at local[2].

Verified Compliance Points:

  1. ✅ Implicit index 2 correctly decoded (BytecodeParser.java:422)
  2. ✅ 8-bit index normal; 16-bit after wide (parser lines 827-872)
  3. ✅ Category-1 local slot (single slot for reference)
  4. ✅ Stack pop of 1 reference (category 1)
  5. ✅ Local offset calculation matches verifier frame model (all three X86StackFrame.getEbpOffset)
  6. ✅ Type propagation: REFERENCE/Operand.REFERENCE throughout
  7. ⚠️ returnAddress not handled (jsr/ret unsupported in L2) — acceptable deviation

Closes #218

New%20session%20-%202026-06-20T20%3A57%3A32.306Z
opencode session  |  github run

Co-authored-by: LSantha <LSantha@users.noreply.github.com>
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.

JVM instruction spec compliance: astore_2

0 participants