diff options
author | James Iry <jamesiry@gmail.com> | 2013-02-24 06:28:45 -0800 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-02-25 16:09:33 -0800 |
commit | 4f2d784a09e5df244ebbee33d23cf931fcacb740 (patch) | |
tree | 57c23a178881adc61362eb53379b262b09450197 /test/files | |
parent | e9f6511094c1e616719221970a9f3eec39c72905 (diff) | |
download | scala-4f2d784a09e5df244ebbee33d23cf931fcacb740.tar.gz scala-4f2d784a09e5df244ebbee33d23cf931fcacb740.tar.bz2 scala-4f2d784a09e5df244ebbee33d23cf931fcacb740.zip |
SI-7006 Simplify jump-only block destination determination
With proper reachability analysis, the code for finding the final
destination of jump-only blocks was more complicated than needed. This
commit simplifies and speeds up that process using a standard
Tortoise and Hare algorithm on a Map from jump-only blocks to their
immediate destinations.
Test t7006 is increased a bit to make sure we don't get stuck on
infinite loops and to make sure we're deleting all but the essential
jump.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/jvm/t7006/Foo_1.scala | 3 | ||||
-rw-r--r-- | test/files/jvm/t7006/Test.scala | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/test/files/jvm/t7006/Foo_1.scala b/test/files/jvm/t7006/Foo_1.scala index f84269daf2..995619ce6b 100644 --- a/test/files/jvm/t7006/Foo_1.scala +++ b/test/files/jvm/t7006/Foo_1.scala @@ -1,9 +1,10 @@ class Foo_1 { def foo { try { - val x = 3 + val x = 3 // this will be optimized away, leaving a useless jump only block } finally { print("hello") } + while(true){} // ensure infinite loop doesn't break the algoirthm } } diff --git a/test/files/jvm/t7006/Test.scala b/test/files/jvm/t7006/Test.scala index 5cc38e42a2..065a23510e 100644 --- a/test/files/jvm/t7006/Test.scala +++ b/test/files/jvm/t7006/Test.scala @@ -7,12 +7,13 @@ object Test extends BytecodeTest { def show: Unit = { val classNode = loadClassNode("Foo_1") val methodNode = getMethod(classNode, "foo") - assert(countNops(methodNode.instructions) == 0) + assert(count(methodNode.instructions, asm.Opcodes.NOP) == 0) + assert(count(methodNode.instructions, asm.Opcodes.GOTO) == 1) } - def countNops(insnList: InsnList): Int = { + def count(insnList: InsnList, opcode: Int): Int = { def isNop(node: asm.tree.AbstractInsnNode): Boolean = - (node.getOpcode == asm.Opcodes.NOP) + (node.getOpcode == opcode) insnList.iterator.asScala.count(isNop) } } |