Fix DUPn_Xm handling in PopBackwardPropagationTransformer

DUPn_Xm instructions implicitly depend on elements directly under stack
top (which are not "copied", but still required). We can't analyze them
precisely now, and should skip methods containing these instructions.
Fortunately, we didn't generate these instructions under POP before,
but with new range check code generation and constant conditions
elimination such combination of instructions becomes possible.
This commit is contained in:
Dmitry Petrov
2017-07-05 15:40:30 +03:00
parent 4480a9bdfb
commit b693b54a2c
@@ -33,9 +33,17 @@ import java.util.*
class PopBackwardPropagationTransformer : MethodTransformer() {
override fun transform(internalClassName: String, methodNode: MethodNode) {
if (!OptimizationMethodVisitor.canBeOptimizedUsingSourceInterpreter(methodNode)) return
if (methodNode.instructions.toArray().any { it.isUnsafeStackInsn() }) return
Transformer(methodNode).transform()
}
// TODO better stack operations analysis
private fun AbstractInsnNode.isUnsafeStackInsn() =
opcode == Opcodes.DUP_X1 ||
opcode == Opcodes.DUP_X2 ||
opcode == Opcodes.DUP2_X1 ||
opcode == Opcodes.DUP2_X2
private class Transformer(val methodNode: MethodNode) {
private interface Transformation {
fun apply(insn: AbstractInsnNode)