Issue Details (XML | Word | Printable)

Key: JANINO-115
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Arno Unkrig
Reporter: Matt Fowles
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Janino

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

Created: 22/May/08 01:39 PM   Updated: 16/Jun/08 09:28 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Text File wide-branches.patch (34 kB)


Testcase included: yes
Patch Submitted: Yes


 Description  « Hide
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).



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Arno Unkrig added a comment - 22/May/08 06:28 PM
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


Matt Fowles added a comment - 22/May/08 10:58 PM
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.

Arno Unkrig added a comment - 25/May/08 03:35 PM
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.

Arno Unkrig added a comment - 25/May/08 04:11 PM
Will go into the next version of JANINO.

Matt Fowles added a comment - 16/Jun/08 09:28 AM
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.