Skip to content

Fix Java 6 bytecode verification error for complex Brainf*ck programs#21

Merged
making merged 1 commit into
developfrom
fix-java6-bytecode-verification
Jul 11, 2025
Merged

Fix Java 6 bytecode verification error for complex Brainf*ck programs#21
making merged 1 commit into
developfrom
fix-java6-bytecode-verification

Conversation

@making
Copy link
Copy Markdown
Owner

@making making commented Jul 10, 2025

Summary

  • Fix StackMapTable verification error "Expecting a stackmap frame at branch target" for Java 6 bytecode
  • Replace IFEQ/GOTO pattern with IFNE/GOTO_W to handle large branch offsets exceeding 16-bit limits
  • Add proper StackMapTable generation for Java 6 bytecode verification requirements

Problem

Complex Brainfuck programs like mandelbrot.bf were failing with java.lang.VerifyError: Expecting a stackmap frame at branch target 221 when targeting Java 6 or later. The issue was caused by:

  1. Missing StackMapTable attribute required for Java 6+ bytecode verification
  2. Branch offset overflow - large programs exceed 16-bit IFEQ/GOTO offset limits
  3. Incorrect operand order in some bytecode generation methods

Solution

  1. StackMapTable Generation: Added proper StackMapTable with APPEND frames for local variables and SAME_FRAME_EXTENDED for branch targets
  2. Large Offset Handling: Replaced IFEQ/GOTO pattern with IFNE + GOTO_W to support 32-bit offsets for large programs
  3. Fixed Operand Order: Corrected stack operand order in generateSetValueToZeroExpression

Test Results

✅ Simple programs (loop.bf) work correctly
✅ Complex programs (mandelbrot.bf) now generate valid Java 6 bytecode
✅ Generated mandelbrot output matches expected result (48 lines of ASCII art)
✅ All existing functionality preserved

Technical Details

  • Uses GOTO_W (32-bit offsets) instead of GOTO (16-bit) for loop jumps
  • Generates minimal StackMapTable frames for branch targets
  • Maintains Java 6 compatibility (class file version 50)
  • Code optimized and cleaned up - removed trial-and-error artifacts

Resolves #6

🤖 Generated with Claude Code

- Fix StackMapTable verification error "Expecting a stackmap frame at branch target"
- Replace IFEQ/GOTO pattern with IFNE/GOTO_W to handle large branch offsets
- Add proper StackMapTable generation for Java 6 bytecode verification
- Fix operand order in generateSetValueToZeroExpression method
- Support complex programs like mandelbrot.bf that generate large bytecode

Resolves #6

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@making making changed the title Fix Java 6 bytecode verification error for complex Brainfuck programs Fix Java 6 bytecode verification error for complex Brainf*ck programs Jul 10, 2025
@making making merged commit 9ac29fa into develop Jul 11, 2025
0 of 6 checks passed
@making making deleted the fix-java6-bytecode-verification branch July 11, 2025 01:18
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.

Compile mandelbrot.bf to mandelbrot.class doesn't work

1 participant