sipkab / jvm-tail-recursion Goto Github PK
View Code? Open in Web Editor NEWOptimizer library for tail recursive calls in Java bytecode
License: GNU General Public License v3.0
Optimizer library for tail recursive calls in Java bytecode
License: GNU General Public License v3.0
Are there any benchmarks showing the effect of applying the tail-recursion optimizations?
There may be cases when a tail recursive call has multiple execution paths after the call itself. The optimization should be performed in cases where it is possible.
One example is such:
public static int count(int n) {
if (n == 0) {
return 0;
}
int v = count(n - 1);
if (n == 0) {
callSomeOtherMethod();
}
return v;
}
Should be optimized to:
public static int count(int n) {
start:
if (n == 0) {
return 0;
}
if (n == 0) {
int v = count(n - 1);
callSomeOtherMethod();
return v;
}
n = n - 1;
goto start;
}
Current state
Currently we allow branches to be present in the return path, but they all need to be side-effect free. This issue requires individual modifications and analysis to the subsequent execution paths.
I wonder how does this compare to kotlin tailrec keyword implementation.
Seems like this would be a good spotbugs check to identify recursion that could easily be improved by the programmer. Spotbugs doesn't modify the output but can produce a warning when such a condition exists which would be helpful.
I'm getting this error:
Exception in thread "main" java.lang.IllegalArgumentException: Class versions V1_5 or less must use F_NEW frames.
at sipka.jvm.tailrec.thirdparty.org.objectweb.asm.MethodWriter.visitFrame(MethodWriter.java:779)
at sipka.jvm.tailrec.thirdparty.org.objectweb.asm.tree.FrameNode.accept(FrameNode.java:141)
at sipka.jvm.tailrec.thirdparty.org.objectweb.asm.tree.InsnList.accept(InsnList.java:145)
at sipka.jvm.tailrec.thirdparty.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:752)
at sipka.jvm.tailrec.thirdparty.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:650)
at sipka.jvm.tailrec.thirdparty.org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:466)
at sipka.jvm.tailrec.TailRecursionOptimizer.optimizeMethods(TailRecursionOptimizer.java:114)
at sipka.jvm.tailrec.TailRecursionOptimizer.optimizeMethods(TailRecursionOptimizer.java:92)
at sipka.jvm.tailrec.MainCommand.optimizeJar(MainCommand.java:208)
at sipka.jvm.tailrec.MainCommand.optimizeFile(MainCommand.java:182)
at sipka.jvm.tailrec.MainCommand.call(MainCommand.java:139)
at sipka.jvm.tailrec.Main.lambda$parse$1(Main.java:166)
at sipka.jvm.tailrec.Main.callCommand(Main.java:195)
at sipka.jvm.tailrec.Main.main(Main.java:177)
Version: v0.8.1
Java version used to run: Java 15
The target JAR uses Java 8 as far as I know, but it has some libraries that should be backwards compatible or such for my understanding, otherwise who would on the earth still uses Java 5? There is Java 15!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.