L1A/L1B: FAIL (phys stack bug); L2: PARTIAL (unsupported)#552
Open
opencode-agent[bot] wants to merge 1 commit into
Open
L1A/L1B: FAIL (phys stack bug); L2: PARTIAL (unsupported)#552opencode-agent[bot] wants to merge 1 commit into
opencode-agent[bot] wants to merge 1 commit into
Conversation
Co-authored-by: LSantha <LSantha@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spec compliance report
Details
JVM Spec Reference
dup2_x2(opcode 0x5e = 94)Category 1:
int,float,reference(single slot). Category 2:long,double(double slot).l1a Implementation
core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:1670,core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java,core/src/core/org/jnode/vm/x86/compiler/l1a/ItemStack.javaPhysical stack manipulation bug (lines 1681-1691): The code always executes a fixed register-based POP/PUSH sequence assuming exactly 4 values on the physical stack. This is only correct for Form 1 (4 category-1 values). For Form 2 (3 values), Form 3 (3 values), and Form 4 (2 values), this incorrectly pops/pushes values below the relevant operands, corrupting the physical stack.
Virtual stack logic (lines 1693-1729): Correctly handles all 4 forms with proper category checks. The virtual stack updates match the spec for all forms.
Forced stack flush:
vstack.push(eContext)at line 1674 flushes all virtual items to physical stack before manipulation, but the subsequent register manipulation doesn't account for variable operand counts per form.l1b Implementation
core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:2002(NEW),:1933(OLD, commented),core/src/core/org/jnode/vm/x86/compiler/l1b/VirtualStack.java,core/src/core/org/jnode/vm/x86/compiler/l1b/ItemStack.javaPhysical stack manipulation bug (lines 2014-2024): Identical bug to l1a - same fixed 4-pop/6-push register sequence that only works for Form 1.
NEW virtual stack logic (lines 2026-2066): Improved over l1a. Checks
c1(top value) first, correctly handles all 4 forms with more readable logic.OLD virtual stack logic (lines 1933-1995, commented): Same as l1a.
Debug output: Line 2007 prints "NEW dup2_x2" to stdout - should be removed in production.
l2 Implementation
core/src/core/org/jnode/vm/x86/compiler/l2/L2ByteCodeSupportChecker.java:131,core/src/core/org/jnode/vm/compiler/ir/IRGenerator.java:574Explicitly unsupported in L2ByteCodeSupportChecker (line 131-133):
notSupported()call rejects methods withdup2_x2from L2 compilation.IRGenerator throws exception (line 574-576):
IllegalArgumentException("byte code not yet supported")- even if support checker were modified, IR generation would fail.Impact: Methods with
dup2_x2fall back to L1 compilation only. Known limitation, not a correctness bug, but incomplete L2 coverage.Root Cause Analysis
The fundamental issue in L1A/L1B is the "push all on stack" fallback strategy (comment: "since this opcode is just too complicated"). The compilers flush the virtual stack to the physical stack, then attempt a register-based shuffle assuming the maximum operand count (Form 1: 4 values) rather than adapting to the actual form.
The virtual stack tracking in both L1A and L1B is spec-compliant; only the physical code emission is broken.
Recommendation
dup2_x2handling toL2ByteCodeSupportCheckerandIRGenerator, then implement inGenericX86CodeGenerator/X86CodeGenerator.dup2_x2.Closes #257
opencode session | github run