Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split really large methods #19

Closed
cretz opened this issue Jul 26, 2018 · 4 comments
Closed

Split really large methods #19

cretz opened this issue Jul 26, 2018 · 4 comments
Milestone

Comments

@cretz
Copy link
Owner

cretz commented Jul 26, 2018

Yay, another fun algorithm. Currently on the JVM a method size cannot exceed 65535 bytes. Otherwise, with ASM at least, you get the dreaded Method code too large!. Some other JVM languages don't implement code splitting because it's too rare/complex, but we probably need to. At least one generic impl is here (see specifically this package and these tests) but I think I can do better.

I need to decide whether I want to split at the WASM level or the JVM level. Probably the former since we have an insn reworking step that counts stack depth anyways. Either way, I figure while the method is too large, we'll just walk the insns finding a large enough section to pull out. Then pull it out to a synthetic method w/ the params as the stack and the result set if needed. The rules for a section to find is probably where many stack values come down to one/zero, no locals are accessed, and all contained within a block.

While this might not be good enough for generic JVM uses, it should be good enough for me.

@cretz
Copy link
Owner Author

cretz commented Jul 29, 2018

There's some kind of bug that still exists here that is not setting the stack properly. Still working...

@cretz
Copy link
Owner Author

cretz commented Aug 7, 2018

Ok, I think I need to change tack here. Currently this runs a de-dupe algorithm which can also reduce overall size among other things. However, it is quite complicated.

To solve this specific problem, I need to just find the largest non-jumping section of code I can (but still within some % of overall size), save off the stack and locals, call the fn, restore the stack and locals and go from there.

@cretz
Copy link
Owner Author

cretz commented Aug 14, 2018

I created a new algorithm to do this: https://github.com/cretz/msplit. I plan on embedding that code in here, using CodeSizeEvaluator to determine when it's needed, and call it in a loop until the methods come down to size.

@cretz
Copy link
Owner Author

cretz commented Sep 13, 2018

Decided to just react to MethodTooLargeException instead of using the code size evaluator. Will run some more tests before closing this..

@cretz cretz closed this as completed in b079b4a Oct 4, 2018
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

No branches or pull requests

1 participant