Skip to content

@Inherits annotation generates incorrect bytecode resulting in stack overflow #292

@raner

Description

@raner

The @Inherits annotation generates code that invokes the inherited method via invokevirtual, which leads to a mutual recursion between the generated method and its synthetic bridge method:

public fxx.natives.Real minus(fxx.natives.Real);
    descriptor: (Lfxx/natives/Real;)Lfxx/natives/Real;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: aload_1
         2: checkcast     #49                 // class fxx/lang/Invertible
         5: invokevirtual #55                 // Method minus:(Lfxx/lang/Invertible;)Lfxx/lang/Invertible;
         8: checkcast     #7                  // class fxx/natives/Real
        11: areturn

  public fxx.lang.Invertible minus(fxx.lang.Invertible);
    descriptor: (Lfxx/lang/Invertible;)Lfxx/lang/Invertible;
    flags: (0x1041) ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: aload_1
         2: checkcast     #7                  // class fxx/natives/Real
         5: invokevirtual #57                 // Method minus:(Lfxx/natives/Real;)Lfxx/natives/Real;
         8: checkcast     #49                 // class fxx/lang/Invertible
        11: areturn

The fix for this problem is not completely clear at this point, but most likely involves using invokespecial to invoke the desired inherited method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions