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/compiler/scala/tools/nsc/settings/ScalaSettings.scala | |
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/compiler/scala/tools/nsc/settings/ScalaSettings.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/ScalaSettings.scala | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 91b03869e5..98eb831a9d 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -211,7 +211,7 @@ trait ScalaSettings extends AbsScalaSettings private def removalIn212 = "This flag is scheduled for removal in 2.12. If you have a case where you need this flag then please report a bug." - object YstatisticsPhases extends MultiChoiceEnumeration { val parser, typer, patmat, erasure, cleanup = Value } + object YstatisticsPhases extends MultiChoiceEnumeration { val parser, typer, patmat, erasure, cleanup, jvm = Value } val Ystatistics = { val description = "Print compiler statistics for specific phases" MultiChoiceSetting( |