Skip to content
This repository was archived by the owner on Feb 23, 2018. It is now read-only.

Commit 3c4f948

Browse files
committed
Eliminate unreachable code in GenBCode
We rely on dead code elimination provided by the ASM framework, as described in the ASM User Guide (http://asm.ow2.org/index.html), Section 8.2.1. It runs a data flow analysis, which only computes information for reachable instructions. Instructions for which no data is available after the analyis are unreachable. There's one issue with the ASM framework (or the way we use it): Data flow analysis requires the maxlocals and maxstack of each method to be computed. The ASM framework calculates these maxes only when writing the classfiles, not during code generation. In order to run DCE, we therefore run a MethodWriter beforehand on every method. This assings the MethodNode's maxStack/maxLocals, but it does more work (writes the instructions to a byte array). This is also what Miguel uses on his branch. The change is basically the same as lrytz/scala@bfadf92c20. We could probably make this faster (and allocate less memory) by hacking the ASM framework: create a subclass of MethodWriter with a /dev/null byteVector. Another option would be to create a separate visitor for computing those values, duplicating the functionality from the MethodWriter. For now, I added some timers to be able to measure the time DCE takes. Here's compiling the library with -Ystatistics:jvm time in backend : 1 spans, 6597ms bcode initialization : 1 spans, 8ms (0.1%) code generation : 1 spans, 4580ms (69.4%) dead code elimination : 3771 spans, 742ms (11.2%) classfile writing : 1 spans, 879ms (13.3%)
1 parent 1fa441c commit 3c4f948

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/scala/tools/asm/MethodWriter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @author Eric Bruneton
3838
* @author Eugene Kuleshov
3939
*/
40-
class MethodWriter extends MethodVisitor {
40+
public class MethodWriter extends MethodVisitor {
4141

4242
/**
4343
* Pseudo access flag used to denote constructors.
@@ -235,11 +235,19 @@ class MethodWriter extends MethodVisitor {
235235
*/
236236
private int maxStack;
237237

238+
public int getMaxStack() {
239+
return maxStack;
240+
}
241+
238242
/**
239243
* Maximum number of local variables for this method.
240244
*/
241245
private int maxLocals;
242246

247+
public int getMaxLocals() {
248+
return maxLocals;
249+
}
250+
243251
/**
244252
* Number of local variables in the current stack map frame.
245253
*/

0 commit comments

Comments
 (0)