Janino

Methods that compile to more than 32 KB of bytecode cannot be compiled

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

Description

Methods that compile to more than 32 KB of bytecode cannot be compiled.

The attached patch both implements and tests this behavior. The strategy is as follows:

When a branch requires >32K jump, it expands performing a negated jump as follows:

Unexpanded
[if cond offset]

expands to

Expanded
[if !cond skip_goto]
[GOTO_W offset]




As a concrete example,

Unexpanded
IFGT offset

becomes

Expanded
IFLE 8
GOTO_W offset

This requires that branches be allowed to change the size of bytecode when relocate() is called. To account for this, in CodeContext the methods fixup() and relocate() are made private, and a public method fixUpAndRelocate() is added.

The fixUpAndRelocate() method handles check calling fixUpAndRelocate() in a loop while the branches stabilize. A loop is required because it is theoretically possible for the expansion of a later branch to push an earlier branch over the 32K limit and cause it to switch modes, which would then require it to grow, which could trigger an earlier branch to need to expand... In practice, the loop will almost always run 1 or 2 iterations (depending on whether anything needed to grow at all).

Activity

Hide
Arno Unkrig added a comment -

Cool stuff! Will merge it in the next days.

Why do you change Offset.offset from SHORT to INT? We can't go beyond 64K, do we?

CU

Arno

Show
Arno Unkrig added a comment - Cool stuff! Will merge it in the next days. Why do you change Offset.offset from SHORT to INT? We can't go beyond 64K, do we? CU Arno
Hide
Matt Fowles added a comment -

You need to use an int so you can track positive values in the range [32K, 64K] and negative values in the range [-32k, -64k]. Also, it simplifies a bunch of code all over, as you don't have to mask off the sign bit everywhere.

Show
Matt Fowles added a comment - You need to use an int so you can track positive values in the range [32K, 64K] and negative values in the range [-32k, -64k]. Also, it simplifies a bunch of code all over, as you don't have to mask off the sign bit everywhere.
Hide
Arno Unkrig added a comment -

Ah yes, you're right. Actually, code attributes could grow up to 2G, with the restriction that no exception table entries (TRY CATCH FINALLY, SYNCHRONIZED) must appear beyond offset 64K, and no line number info and local variable info can be given after offset 64K.

Show
Arno Unkrig added a comment - Ah yes, you're right. Actually, code attributes could grow up to 2G, with the restriction that no exception table entries (TRY CATCH FINALLY, SYNCHRONIZED) must appear beyond offset 64K, and no line number info and local variable info can be given after offset 64K.
Hide
Arno Unkrig added a comment -

Will go into the next version of JANINO.

Show
Arno Unkrig added a comment - Will go into the next version of JANINO.
Hide
Matt Fowles added a comment -

Arno, I do not have the ability to close this issue. I think my login to Jira does not have the power. You can consider this closed.

Show
Matt Fowles added a comment - Arno, I do not have the ability to close this issue. I think my login to Jira does not have the power. You can consider this closed.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: