Static java optimizer bytecode (e.g. proguard) with escape analysis?

Optimization based on evacuation analysis is a planned feature for Proguard. Meanwhile, are there any existing tools, such as proguard, that are already performing optimizations that require escape analysis?

+6
java scala proguard escape-analysis
source share
2 answers

Yes, I think the Soot framework is doing an escape code analysis.

+3
source share

What do you expect from comp-level escape analysis? Java classes are more like object files in C - they are linked in the JVM, so evacuation analysis can be performed only at the level of one method, which has limited convenience and will prevent debugging (for example, you will have lines of code through which you cannot do it).

In Java design, the compiler is pretty stupid - it checks for correctness (like Lint), but doesn't try to optimize. Intelligent parts are placed in the JVM - it uses several optimization methods to get well-executed code on the current platform in the current environment. Since the JVM knows all the code currently loaded, it can take much more than the compiler and perform speculative optimizations that return when the assumptions are invalid. HotSpot JVM can replace the code with a more optimized version "on the fly" while the function is running (for example, in the middle of the loop when the code becomes "hot").

When not in the debugger, variables with non-overlapping lifetimes are reset, invariants exit cycles, cycle sweeps, etc. All this happens in the JIT code and is executed depending on how much time is spent on this function (it makes no sense to spend time optimizing the code that never runs). If we perform some of these optimizations in advance, the JIT will have less freedom, and the overall result may be negative.

Another optimization is the distribution of the stack of objects that do not miss the current method - this is done in some cases, although I read the document somewhere that the time for a thorough analysis of the evacuation and the time obtained by the optimization suggests that this is not worth it, therefore the current The strategy is more heuristic.

In general, the more JVM information about your source code, the better it can optimize it. And the optimizations that the JVM does are constantly being improved, so I would only think about compiled code optimizations when talking about very limited and basic JVMs like mobile phones. In these cases, you want to run the application through obfuscator anyway (to shorten class names, etc.).

+1
source share

All Articles