diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2014-08-22 09:50:44 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2014-09-09 23:56:52 +0200 |
commit | 90781e874adb1af44a43d3e64d403230970b423d (patch) | |
tree | df7e054a165e0026e6b69bee03c13ea670d96990 /src/asm | |
parent | a3dfb43263a9d29d47f34ad8d183f7a01f3a1ea7 (diff) | |
download | scala-90781e874adb1af44a43d3e64d403230970b423d.tar.gz scala-90781e874adb1af44a43d3e64d403230970b423d.tar.bz2 scala-90781e874adb1af44a43d3e64d403230970b423d.zip |
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 https://github.com/lrytz/scala/commit/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%)
Diffstat (limited to 'src/asm')
-rw-r--r-- | src/asm/scala/tools/asm/MethodWriter.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/asm/scala/tools/asm/MethodWriter.java b/src/asm/scala/tools/asm/MethodWriter.java index 0c4130e499..d30e04c625 100644 --- a/src/asm/scala/tools/asm/MethodWriter.java +++ b/src/asm/scala/tools/asm/MethodWriter.java @@ -37,7 +37,7 @@ package scala.tools.asm; * @author Eric Bruneton * @author Eugene Kuleshov */ -class MethodWriter extends MethodVisitor { +public class MethodWriter extends MethodVisitor { /** * Pseudo access flag used to denote constructors. @@ -235,11 +235,19 @@ class MethodWriter extends MethodVisitor { */ private int maxStack; + public int getMaxStack() { + return maxStack; + } + /** * Maximum number of local variables for this method. */ private int maxLocals; + public int getMaxLocals() { + return maxLocals; + } + /** * Number of local variables in the current stack map frame. */ |