summaryrefslogtreecommitdiff
path: root/test/files/jvm/t7006
diff options
context:
space:
mode:
authorJames Iry <jamesiry@gmail.com>2013-02-22 15:33:18 -0800
committerJames Iry <jamesiry@gmail.com>2013-02-25 16:06:16 -0800
commite9f6511094c1e616719221970a9f3eec39c72905 (patch)
tree39637a515bb941559667f6a32cc5714e8d6d78ac /test/files/jvm/t7006
parent0d2e19cc4c639c27a93c3ed76d892b16d40dcc9b (diff)
downloadscala-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/jvm/t7006')
-rw-r--r--test/files/jvm/t7006/Foo_1.flags1
-rw-r--r--test/files/jvm/t7006/Foo_1.scala9
-rw-r--r--test/files/jvm/t7006/Test.scala18
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)
+ }
+}