l1a/l1b: 32-bit OK, 64-bit broken; l2: broken#550
Open
opencode-agent[bot] wants to merge 1 commit into
Open
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
l1a Implementation
core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:1564(visit_dstore)core/src/core/org/jnode/vm/x86/compiler/l1a/X86BytecodeVisitor.java:455(dwstore)core/src/core/org/jnode/vm/x86/compiler/l1a/X86StackFrame.java:351(getWideEbpOffset)core/src/core/org/jnode/vm/x86/compiler/l1a/VirtualStack.java:135(pop(int type))dstore_3(opcode 0x4A).BytecodeParser(line 413) dispatches tovisit_dstore(3).dwstorecomputes offset viagetWideEbpOffset(3)→getEbpOffset(4)(slot 4, the high slot of the double). In 32-bit mode (slotSize=4), stores LSB todisp+LSB(slot 4, lower address) and MSB todisp+MSB(slot 3, higher address) — matching little-endian layout with downward-growing stack. Type validated byvstack.pop(JvmType.DOUBLE).getWideEbpOffsetstill returnsgetEbpOffset(index+1)(offset for slot 4). The 64-bit path (os.writeMOV(BITS64, helper.BP, disp, reg)) writes 8 bytes at slot 4's location only, covering slots 4–5 instead of the required slots 3–4. The commented code atX86StackFrame.java:353-357shows the intended fix: usegetEbpOffset(index)for 64-bit mode.l1b Implementation
core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:1806(visit_dstore)core/src/core/org/jnode/vm/x86/compiler/l1b/X86BytecodeVisitor.java:461(dwstore)core/src/core/org/jnode/vm/x86/compiler/l1b/X86StackFrame.java:343(getWideEbpOffset)core/src/core/org/jnode/vm/x86/compiler/l1b/VirtualStack.java:135(pop(int type))l2 Implementation
core/src/core/org/jnode/vm/compiler/ir/IRGenerator.java:408(visit_dstore)core/src/core/org/jnode/vm/x86/compiler/l2/GenericX86CodeGenerator.java:278(generateCodeFor(VariableRefAssignQuad))core/src/core/org/jnode/vm/x86/compiler/l2/L2ByteCodeSupportChecker.java(novisit_dstoreoverride → supported by default)IRGenerator.visit_dstorecorrectly decrementsstackOffsetby 2 (category-2) and marks bothvariables[index]andvariables[stackOffset]asOperand.DOUBLE. However, it creates only a singleVariableRefAssignQuadfromstackOffsettoindex, referencing only the first of the two stack slots.GenericX86CodeGenerator.generateCodeFor(VariableRefAssignQuad)handlesLongConstantcorrectly (emits two 32-bitMOVatdisp1 - SLOTSIZEanddisp1, lines 320-325). For non-constant values (REGISTER, STACK, TOPS addressing modes), it emits only a single 32-bitMOV/PUSH/POP(lines 329-340), truncating the double to 32 bits. No type-based branching exists forOperand.DOUBLE/Operand.LONG.L2ByteCodeSupportCheckerdoes not overridevisit_dstore, so it inherits the no-op implementation fromBytecodeVisitorSupport(line 284), markingdstoreas supported. The L2 compiler will attempt to compile methods containingdstore_3but produce incorrect native code for non-constant double values.JVM Spec References:
dstore_3format: opcode 74 (0x4A), no operands, implicit index 3..., value → ...(pops one category-2doublevalue)Closes #252
opencode session | github run