diff options
author | James Iry <jamesiry@gmail.com> | 2013-02-22 15:33:18 -0800 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-02-25 16:06:16 -0800 |
commit | e9f6511094c1e616719221970a9f3eec39c72905 (patch) | |
tree | 39637a515bb941559667f6a32cc5714e8d6d78ac /test/files | |
parent | 0d2e19cc4c639c27a93c3ed76d892b16d40dcc9b (diff) | |
download | scala-e9f6511094c1e616719221970a9f3eec39c72905.tar.gz scala-e9f6511094c1e616719221970a9f3eec39c72905.tar.bz2 scala-e9f6511094c1e616719221970a9f3eec39c72905.zip |
SI-7006 Eliminate unreachable blocks
GenASM was doing a bunch of stuff to eliminate unreachable exception
handlers, but it was still leaving behind other unreachable blocks, for
instance a finally block associated with an exception handler that got
removed would still be left lying around. ASM would in turn turn those
into a big pile of NOPs, which just take up space uselessly.
This commit replaces all the logic for eliding exception handlers with
a single unreachable block remover that catches unused exception
handlers and a whole lot more.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/jvm/t7006/Foo_1.flags | 1 | ||||
-rw-r--r-- | test/files/jvm/t7006/Foo_1.scala | 9 | ||||
-rw-r--r-- | test/files/jvm/t7006/Test.scala | 18 |
3 files changed, 28 insertions, 0 deletions
diff --git a/test/files/jvm/t7006/Foo_1.flags b/test/files/jvm/t7006/Foo_1.flags new file mode 100644 index 0000000000..72fe7b1aa0 --- /dev/null +++ b/test/files/jvm/t7006/Foo_1.flags @@ -0,0 +1 @@ + -Ydead-code -Ydebug -Xfatal-warnings diff --git a/test/files/jvm/t7006/Foo_1.scala b/test/files/jvm/t7006/Foo_1.scala new file mode 100644 index 0000000000..f84269daf2 --- /dev/null +++ b/test/files/jvm/t7006/Foo_1.scala @@ -0,0 +1,9 @@ +class Foo_1 { + def foo { + try { + val x = 3 + } finally { + print("hello") + } + } +} diff --git a/test/files/jvm/t7006/Test.scala b/test/files/jvm/t7006/Test.scala new file mode 100644 index 0000000000..5cc38e42a2 --- /dev/null +++ b/test/files/jvm/t7006/Test.scala @@ -0,0 +1,18 @@ +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import asm.tree.InsnList +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + assert(countNops(methodNode.instructions) == 0) + } + + def countNops(insnList: InsnList): Int = { + def isNop(node: asm.tree.AbstractInsnNode): Boolean = + (node.getOpcode == asm.Opcodes.NOP) + insnList.iterator.asScala.count(isNop) + } +} |