Commit 1f6020a3 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch 'lrytz/asm-branch-sensitive'

parents fea3c514 788d0111
Pipeline #3211 passed with stage
in 8 minutes and 3 seconds
......@@ -190,10 +190,12 @@ public class Analyzer<V extends Value> implements Opcodes {
if (insnNode instanceof JumpInsnNode) {
JumpInsnNode jumpInsn = (JumpInsnNode) insnNode;
if (insnOpcode != GOTO && insnOpcode != JSR) {
currentFrame.initJumpTarget(insnOpcode, /* target = */ null);
merge(insnIndex + 1, currentFrame, subroutine);
newControlFlowEdge(insnIndex, insnIndex + 1);
}
int jumpInsnIndex = insnList.indexOf(jumpInsn.label);
currentFrame.initJumpTarget(insnOpcode, jumpInsn.label);
if (insnOpcode == JSR) {
merge(
jumpInsnIndex,
......@@ -206,20 +208,26 @@ public class Analyzer<V extends Value> implements Opcodes {
} else if (insnNode instanceof LookupSwitchInsnNode) {
LookupSwitchInsnNode lookupSwitchInsn = (LookupSwitchInsnNode) insnNode;
int targetInsnIndex = insnList.indexOf(lookupSwitchInsn.dflt);
currentFrame.initJumpTarget(insnOpcode, lookupSwitchInsn.dflt);
merge(targetInsnIndex, currentFrame, subroutine);
newControlFlowEdge(insnIndex, targetInsnIndex);
for (int i = 0; i < lookupSwitchInsn.labels.size(); ++i) {
targetInsnIndex = insnList.indexOf(lookupSwitchInsn.labels.get(i));
LabelNode label = lookupSwitchInsn.labels.get(i);
targetInsnIndex = insnList.indexOf(label);
currentFrame.initJumpTarget(insnOpcode, label);
merge(targetInsnIndex, currentFrame, subroutine);
newControlFlowEdge(insnIndex, targetInsnIndex);
}
} else if (insnNode instanceof TableSwitchInsnNode) {
TableSwitchInsnNode tableSwitchInsn = (TableSwitchInsnNode) insnNode;
int targetInsnIndex = insnList.indexOf(tableSwitchInsn.dflt);
currentFrame.initJumpTarget(insnOpcode, tableSwitchInsn.dflt);
merge(targetInsnIndex, currentFrame, subroutine);
newControlFlowEdge(insnIndex, targetInsnIndex);
for (int i = 0; i < tableSwitchInsn.labels.size(); ++i) {
targetInsnIndex = insnList.indexOf(tableSwitchInsn.labels.get(i));
LabelNode label = tableSwitchInsn.labels.get(i);
currentFrame.initJumpTarget(insnOpcode, label);
targetInsnIndex = insnList.indexOf(label);
merge(targetInsnIndex, currentFrame, subroutine);
newControlFlowEdge(insnIndex, targetInsnIndex);
}
......
......@@ -34,6 +34,7 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.IincInsnNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
......@@ -101,6 +102,26 @@ public class Frame<V extends Value> {
return this;
}
/**
* Initializes a frame corresponding to the target or to the successor of a jump instruction. This
* method is called by {@link Analyzer#analyze(String, org.objectweb.asm.tree.MethodNode)} while
* interpreting jump instructions. It is called once for each possible target of the jump
* instruction, and once for its successor instruction (except for GOTO and JSR), before the frame
* is merged with the existing frame at this location. The default implementation of this method
* does nothing.
*
* <p>Overriding this method and changing the frame values allows implementing branch-sensitive
* analyses.
*
* @param opcode the opcode of the jump instruction. Can be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE,
* IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE,
* GOTO, JSR, IFNULL, IFNONNULL, TABLESWITCH or LOOKUPSWITCH.
* @param target a target of the jump instruction this frame corresponds to, or {@literal null} if
* this frame corresponds to the successor of the jump instruction (i.e. the next instruction
* in the instructions sequence).
*/
public void initJumpTarget(final int opcode, final LabelNode target) {}
/**
* Sets the expected return type of the analyzed method.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment