Remove empty try-catch blocks in DCE

Signed-off-by: Major <major@emulate.rs>
master
Major 5 years ago
parent 9b5d4221b1
commit a9312f3cd2
  1. 14
      asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt
  2. 4
      asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt

@ -9,6 +9,7 @@ import org.objectweb.asm.tree.LabelNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.LookupSwitchInsnNode
import org.objectweb.asm.tree.TableSwitchInsnNode
import org.objectweb.asm.tree.TryCatchBlockNode
import org.objectweb.asm.util.Textifier
import org.objectweb.asm.util.TraceMethodVisitor
import java.io.PrintWriter
@ -306,3 +307,16 @@ fun AbstractInsnNode.toPrettyString(): String {
}
}
}
fun TryCatchBlockNode.isBodyEmpty(): Boolean {
var current = start.next
while (true) {
when {
current == null -> return false
current === end -> return true
current.opcode != -1 -> return false
else -> current = current.next
}
}
}

@ -125,7 +125,9 @@ fun MethodNode.removeDeadCode(owner: String) {
}
}
changed = changed or tryCatchBlocks.removeIf { it.start in deadLabels && it.end in deadLabels }
changed = changed or tryCatchBlocks.removeIf {
it.start in deadLabels && it.end in deadLabels || it.isBodyEmpty()
}
} while (changed)
}

Loading…
Cancel
Save