下面列出了org.objectweb.asm.Opcodes# IFNE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int getInvertedJump(int opcode) {
int i = -1;
switch (opcode) {
case Opcodes.IFEQ:
i = Opcodes.IFNE;
break;
case Opcodes.IFNE:
i = Opcodes.IFEQ;
break;
case Opcodes.IF_ACMPEQ:
i = Opcodes.IF_ACMPNE;
break;
case Opcodes.IF_ACMPNE:
i = Opcodes.IF_ACMPEQ;
break;
}
return i;
}
public static ComparisonType getType(int opcode) {
switch (opcode) {
case Opcodes.IF_ACMPEQ:
case Opcodes.IF_ICMPEQ:
case Opcodes.IFEQ:
return EQ;
case Opcodes.IF_ACMPNE:
case Opcodes.IF_ICMPNE:
case Opcodes.IFNE:
return NE;
case Opcodes.IF_ICMPGT:
case Opcodes.IFGT:
return GT;
case Opcodes.IF_ICMPGE:
case Opcodes.IFGE:
return GE;
case Opcodes.IF_ICMPLT:
case Opcodes.IFLT:
return LT;
case Opcodes.IF_ICMPLE:
case Opcodes.IFLE:
return LE;
default:
throw new IllegalArgumentException(Printer.OPCODES[opcode]);
}
}
public InsnValue compareConstant(AbstractInsnNode insn, InsnValue value) {
if (value.getValue() == null) {
return InsnValue.INT_VALUE;
}
int i = ((Number)value.getValue()).intValue();
switch (insn.getOpcode()) {
case Opcodes.IFEQ:
return InsnValue.intValue(i == 0);
case Opcodes.IFNE:
return InsnValue.intValue(i != 0);
case Opcodes.IFLE:
return InsnValue.intValue(i <= 0);
case Opcodes.IFLT:
return InsnValue.intValue(i < 0);
case Opcodes.IFGE:
return InsnValue.intValue(i >= 0);
case Opcodes.IFGT:
return InsnValue.intValue(i > 0);
}
return null;
}
private boolean canMutate(final int opcode) {
switch (opcode) {
case Opcodes.IFLE:
case Opcodes.IFGE:
case Opcodes.IFGT:
case Opcodes.IFLT:
case Opcodes.IF_ICMPGE:
case Opcodes.IF_ICMPGT:
case Opcodes.IF_ICMPLE:
case Opcodes.IF_ICMPLT:
return (RemoveConditionalMutator.this.kind == Choice.ORDER);
case Opcodes.IFEQ:
case Opcodes.IFNE:
case Opcodes.IFNONNULL:
case Opcodes.IFNULL:
case Opcodes.IF_ICMPNE:
case Opcodes.IF_ICMPEQ:
case Opcodes.IF_ACMPEQ:
case Opcodes.IF_ACMPNE:
return (RemoveConditionalMutator.this.kind == Choice.EQUAL);
default:
return false;
}
}
@Override
public void visitJumpInsn(final int opcode, final Label destination) {
if ((opcode == Opcodes.IFNE) && this.assertBlockStarted) {
this.destination = destination;
this.assertBlockStarted = false;
}
super.visitJumpInsn(opcode, destination);
}
@Override
public void visitJumpInsn(int opcode, Label label) {
switch (opcode) {
case Opcodes.IFEQ:
case Opcodes.IFNE:
case Opcodes.IFLT:
case Opcodes.IFGE:
case Opcodes.IFGT:
case Opcodes.IFLE:
pop();
break;
case Opcodes.IF_ICMPEQ:
case Opcodes.IF_ICMPNE:
case Opcodes.IF_ICMPLT:
case Opcodes.IF_ICMPGE:
case Opcodes.IF_ICMPGT:
case Opcodes.IF_ICMPLE:
case Opcodes.IF_ACMPEQ:
case Opcodes.IF_ACMPNE:
pop(2);
break;
case Opcodes.GOTO:
break;
case Opcodes.JSR:
throw new RuntimeException("The JSR instruction is not supported.");
case Opcodes.IFNULL:
case Opcodes.IFNONNULL:
pop(1);
break;
default:
throw new RuntimeException("Unhandled opcode " + opcode);
}
super.visitJumpInsn(opcode, label);
}
@Override
public void visitJumpInsn(int arg0, Label arg1) {
savePreviousFrame();
switch (arg0) {
case Opcodes.IF_ACMPEQ:
case Opcodes.IF_ACMPNE:
case Opcodes.IF_ICMPEQ:
case Opcodes.IF_ICMPGE:
case Opcodes.IF_ICMPGT:
case Opcodes.IF_ICMPLE:
case Opcodes.IF_ICMPLT:
case Opcodes.IF_ICMPNE:
currentFrame.popStack();
case Opcodes.IFEQ:
case Opcodes.IFGE:
case Opcodes.IFGT:
case Opcodes.IFLE:
case Opcodes.IFLT:
case Opcodes.IFNE:
case Opcodes.IFNONNULL:
case Opcodes.IFNULL:
currentFrame.popStack();
case Opcodes.GOTO:
forwardFrames.put(arg1, new StackInfo(currentFrame));
break;
case Opcodes.JSR:
currentFrame.pushStack(retAddressType);
forwardFrames.put(arg1, new StackInfo(currentFrame));
break;
default:
logger.debug("Unhandled: ");
}
if (logger.isDebugEnabled())
logger.debug("jumpInsn " + getOpCode(arg0) + " " + arg1);
delegate.visitJumpInsn(arg0, arg1);
}
@Override
public void visitJumpInsn(final int opcode, final Label label) {
switch (opcode) {
case Opcodes.IFEQ:
ifeq(label);
break;
case Opcodes.IFNE:
ifne(label);
break;
case Opcodes.IFLT:
iflt(label);
break;
case Opcodes.IFGE:
ifge(label);
break;
case Opcodes.IFGT:
ifgt(label);
break;
case Opcodes.IFLE:
ifle(label);
break;
case Opcodes.IF_ICMPEQ:
ificmpeq(label);
break;
case Opcodes.IF_ICMPNE:
ificmpne(label);
break;
case Opcodes.IF_ICMPLT:
ificmplt(label);
break;
case Opcodes.IF_ICMPGE:
ificmpge(label);
break;
case Opcodes.IF_ICMPGT:
ificmpgt(label);
break;
case Opcodes.IF_ICMPLE:
ificmple(label);
break;
case Opcodes.IF_ACMPEQ:
ifacmpeq(label);
break;
case Opcodes.IF_ACMPNE:
ifacmpne(label);
break;
case Opcodes.GOTO:
goTo(label);
break;
case Opcodes.JSR:
jsr(label);
break;
case Opcodes.IFNULL:
ifnull(label);
break;
case Opcodes.IFNONNULL:
ifnonnull(label);
break;
default:
throw new IllegalArgumentException();
}
}
@Override
public void visitJumpInsn(final int opcode, final Label label) {
switch (opcode) {
case Opcodes.IFEQ:
ifeq(label);
break;
case Opcodes.IFNE:
ifne(label);
break;
case Opcodes.IFLT:
iflt(label);
break;
case Opcodes.IFGE:
ifge(label);
break;
case Opcodes.IFGT:
ifgt(label);
break;
case Opcodes.IFLE:
ifle(label);
break;
case Opcodes.IF_ICMPEQ:
ificmpeq(label);
break;
case Opcodes.IF_ICMPNE:
ificmpne(label);
break;
case Opcodes.IF_ICMPLT:
ificmplt(label);
break;
case Opcodes.IF_ICMPGE:
ificmpge(label);
break;
case Opcodes.IF_ICMPGT:
ificmpgt(label);
break;
case Opcodes.IF_ICMPLE:
ificmple(label);
break;
case Opcodes.IF_ACMPEQ:
ifacmpeq(label);
break;
case Opcodes.IF_ACMPNE:
ifacmpne(label);
break;
case Opcodes.GOTO:
goTo(label);
break;
case Opcodes.JSR:
jsr(label);
break;
case Opcodes.IFNULL:
ifnull(label);
break;
case Opcodes.IFNONNULL:
ifnonnull(label);
break;
default:
throw new IllegalArgumentException();
}
}
/**
* @param opcode
* @param label
* @param s
* @return
*/
static boolean handleJVMJump ( int opcode, Label label, JVMStackState s ) {
boolean tainted;
switch ( opcode ) {
case Opcodes.IF_ICMPEQ:
case Opcodes.IF_ICMPNE:
case Opcodes.IF_ICMPLT:
case Opcodes.IF_ICMPGE:
case Opcodes.IF_ICMPGT:
case Opcodes.IF_ICMPLE:
case Opcodes.IF_ACMPEQ:
case Opcodes.IF_ACMPNE:
BaseType o1 = s.pop();
BaseType o2 = s.pop();
tainted = ! ( o1 != null ) || ! ( o2 != null ) || o1.isTainted() || o2.isTainted();
break;
case Opcodes.IFEQ:
case Opcodes.IFNE:
case Opcodes.IFLT:
case Opcodes.IFGE:
case Opcodes.IFGT:
case Opcodes.IFLE:
case Opcodes.IFNULL:
case Opcodes.IFNONNULL:
BaseType c = s.pop();
tainted = ( c == null || c.isTainted() );
break;
case Opcodes.JSR:
s.push(new BasicConstant(Type.INT_TYPE, label));
tainted = false;
break;
case Opcodes.GOTO:
tainted = false;
break;
default:
log.warn("Unsupported opcode " + opcode); //$NON-NLS-1$
tainted = true;
}
return tainted;
}
private void pushProductOfIntArrayOnStack() {
Label beginScopeLabel = new Label();
Label endScopeLabel = new Label();
int dimsArrayIndex = newLocal("[I", beginScopeLabel, endScopeLabel);
int counterIndex = newLocal("I", beginScopeLabel, endScopeLabel);
int productIndex = newLocal("I", beginScopeLabel, endScopeLabel);
Label loopLabel = new Label();
Label endLabel = new Label();
super.visitLabel(beginScopeLabel);
// stack: ... intArray
super.visitVarInsn(Opcodes.ASTORE, dimsArrayIndex);
// -> stack: ...
// counter = 0
super.visitInsn(Opcodes.ICONST_0);
super.visitVarInsn(Opcodes.ISTORE, counterIndex);
// product = 1
super.visitInsn(Opcodes.ICONST_1);
super.visitVarInsn(Opcodes.ISTORE, productIndex);
// loop:
super.visitLabel(loopLabel);
// if index >= arraylength goto end:
super.visitVarInsn(Opcodes.ILOAD, counterIndex);
super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
super.visitInsn(Opcodes.ARRAYLENGTH);
super.visitJumpInsn(Opcodes.IF_ICMPGE, endLabel);
// product = product * max(array[counter],1)
super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
super.visitVarInsn(Opcodes.ILOAD, counterIndex);
super.visitInsn(Opcodes.IALOAD);
super.visitInsn(Opcodes.DUP);
Label nonZeroDimension = new Label();
super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension);
super.visitInsn(Opcodes.POP);
super.visitInsn(Opcodes.ICONST_1);
super.visitLabel(nonZeroDimension);
super.visitVarInsn(Opcodes.ILOAD, productIndex);
super.visitInsn(Opcodes.IMUL); // if overflow happens it happens.
super.visitVarInsn(Opcodes.ISTORE, productIndex);
// iinc counter 1
super.visitIincInsn(counterIndex, 1);
// goto loop
super.visitJumpInsn(Opcodes.GOTO, loopLabel);
// end:
super.visitLabel(endLabel);
// re-push dimensions array
super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
// push product
super.visitVarInsn(Opcodes.ILOAD, productIndex);
super.visitLabel(endScopeLabel);
}
void calculateArrayLengthAndDispatch(String typeName, int dimCount) {
// Since the dimensions of the array are not known at instrumentation
// time, we take the created multi-dimensional array and peel off nesting
// levels from the left. For each nesting layer we probe the array length
// and accumulate a partial product which we can then feed the recording
// function.
// below we note the partial product of dimensions 1 to X-1 as productToX
// (so productTo1 == 1 == no dimensions yet). We denote by aref0 the
// array reference at the current nesting level (the containing aref's [0]
// element). If we hit a level whose arraylength is 0 or whose
// reference is null, there's no point continuing, so we shortcut
// out.
// This approach works pretty well when you create a new array with the
// newarray bytecodes. You can also create a new array by cloning an
// existing array; an existing multidimensional array might have had some
// of its [0] elements nulled out. We currently deal with this by bailing
// out, but arguably we should do something more principled (like calculate
// the size of the multidimensional array from scratch if you are using
// clone()).
// TODO(java-platform-team): Do something about modified multidimensional
// arrays and clone().
Label zeroDimension = new Label();
super.visitInsn(Opcodes.DUP); // -> stack: ... origaref aref0
super.visitLdcInsn(1); // -> stack: ... origaref aref0 productTo1
for (int i = 0; i < dimCount; ++i) {
// pre: stack: ... origaref aref0 productToI
super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref productToI aref
super.visitInsn(Opcodes.DUP);
Label nonNullDimension = new Label();
// -> stack: ... origaref productToI aref aref
super.visitJumpInsn(Opcodes.IFNONNULL, nonNullDimension);
// -> stack: ... origaref productToI aref
super.visitInsn(Opcodes.SWAP);
// -> stack: ... origaref aref productToI
super.visitJumpInsn(Opcodes.GOTO, zeroDimension);
super.visitLabel(nonNullDimension);
// -> stack: ... origaref productToI aref
super.visitInsn(Opcodes.DUP_X1);
// -> stack: ... origaref aref0 productToI aref
super.visitInsn(Opcodes.ARRAYLENGTH);
// -> stack: ... origaref aref0 productToI dimI
Label nonZeroDimension = new Label();
super.visitInsn(Opcodes.DUP);
// -> stack: ... origaref aref0 productToI dimI dimI
super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension);
// -> stack: ... origaref aref0 productToI dimI
super.visitInsn(Opcodes.POP);
// -> stack: ... origaref aref0 productToI
super.visitJumpInsn(Opcodes.GOTO, zeroDimension);
super.visitLabel(nonZeroDimension);
// -> stack: ... origaref aref0 productToI max(dimI,1)
super.visitInsn(Opcodes.IMUL);
// -> stack: ... origaref aref0 productTo{I+1}
if (i < dimCount - 1) {
super.visitInsn(Opcodes.SWAP);
// -> stack: ... origaref productTo{I+1} aref0
super.visitInsn(Opcodes.ICONST_0);
// -> stack: ... origaref productTo{I+1} aref0 0
super.visitInsn(Opcodes.AALOAD);
// -> stack: ... origaref productTo{I+1} aref0'
super.visitInsn(Opcodes.SWAP);
}
// post: stack: ... origaref aref0 productTo{I+1}
}
super.visitLabel(zeroDimension);
super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref product aref0
super.visitInsn(Opcodes.POP); // -> stack: ... origaref product
super.visitInsn(Opcodes.SWAP); // -> stack: ... product origaref
invokeRecordAllocation(typeName);
}
@Override
public void visitJumpInsn(final int opcode, final Label label) {
switch (opcode) {
case Opcodes.IFEQ:
ifeq(label);
break;
case Opcodes.IFNE:
ifne(label);
break;
case Opcodes.IFLT:
iflt(label);
break;
case Opcodes.IFGE:
ifge(label);
break;
case Opcodes.IFGT:
ifgt(label);
break;
case Opcodes.IFLE:
ifle(label);
break;
case Opcodes.IF_ICMPEQ:
ificmpeq(label);
break;
case Opcodes.IF_ICMPNE:
ificmpne(label);
break;
case Opcodes.IF_ICMPLT:
ificmplt(label);
break;
case Opcodes.IF_ICMPGE:
ificmpge(label);
break;
case Opcodes.IF_ICMPGT:
ificmpgt(label);
break;
case Opcodes.IF_ICMPLE:
ificmple(label);
break;
case Opcodes.IF_ACMPEQ:
ifacmpeq(label);
break;
case Opcodes.IF_ACMPNE:
ifacmpne(label);
break;
case Opcodes.GOTO:
goTo(label);
break;
case Opcodes.JSR:
jsr(label);
break;
case Opcodes.IFNULL:
ifnull(label);
break;
case Opcodes.IFNONNULL:
ifnonnull(label);
break;
default:
throw new IllegalArgumentException();
}
}
@Override
public void visitJumpInsn(final int opcode, final Label label) {
switch (opcode) {
case Opcodes.IFEQ:
ifeq(label);
break;
case Opcodes.IFNE:
ifne(label);
break;
case Opcodes.IFLT:
iflt(label);
break;
case Opcodes.IFGE:
ifge(label);
break;
case Opcodes.IFGT:
ifgt(label);
break;
case Opcodes.IFLE:
ifle(label);
break;
case Opcodes.IF_ICMPEQ:
ificmpeq(label);
break;
case Opcodes.IF_ICMPNE:
ificmpne(label);
break;
case Opcodes.IF_ICMPLT:
ificmplt(label);
break;
case Opcodes.IF_ICMPGE:
ificmpge(label);
break;
case Opcodes.IF_ICMPGT:
ificmpgt(label);
break;
case Opcodes.IF_ICMPLE:
ificmple(label);
break;
case Opcodes.IF_ACMPEQ:
ifacmpeq(label);
break;
case Opcodes.IF_ACMPNE:
ifacmpne(label);
break;
case Opcodes.GOTO:
goTo(label);
break;
case Opcodes.JSR:
jsr(label);
break;
case Opcodes.IFNULL:
ifnull(label);
break;
case Opcodes.IFNONNULL:
ifnonnull(label);
break;
default:
throw new IllegalArgumentException();
}
}
@Override
public void appendInstruction(StringBuilder b, List<Instruction> instructions) {
b.append(" ");
switch(opcode) {
case Opcodes.IFEQ:
b.append("if(POP_INT() == 0) /* IFEQ */ ");
break;
case Opcodes.IFNE:
b.append("if(POP_INT() != 0) /* IFNE */ ");
break;
case Opcodes.IFLT:
b.append("if(POP_INT() < 0) /* IFLT */ ");
break;
case Opcodes.IFGE:
b.append("if(POP_INT() >= 0) /* IFGE */ ");
break;
case Opcodes.IFGT:
b.append("if(POP_INT() > 0) /* IFGT */ ");
break;
case Opcodes.IFLE:
b.append("if(POP_INT() <= 0) /* IFLE */ ");
break;
case Opcodes.IF_ICMPEQ:
b.append("SP-=2; if((*SP).data.i == SP[1].data.i) /* IF_ICMPEQ */ ");
break;
case Opcodes.IF_ICMPNE:
b.append("SP-=2; if((*SP).data.i != SP[1].data.i) /* IF_ICMPNE */ ");
break;
case Opcodes.IF_ICMPLT:
b.append("SP-=2; if((*SP).data.i < SP[1].data.i) /* IF_ICMPLT */ ");
break;
case Opcodes.IF_ICMPGE:
b.append("SP-=2; if((*SP).data.i >= SP[1].data.i) /* IF_ICMPGE */ ");
break;
case Opcodes.IF_ICMPGT:
b.append("SP-=2; if((*SP).data.i > SP[1].data.i) /* IF_ICMPGT */ ");
break;
case Opcodes.IF_ICMPLE:
b.append("SP-=2; if((*SP).data.i <= SP[1].data.i) /* IF_ICMPLE */ ");
break;
case Opcodes.IF_ACMPEQ:
b.append("SP-=2; if((*SP).data.o == SP[1].data.o) /* IF_ACMPEQ */ ");
break;
case Opcodes.IF_ACMPNE:
b.append("SP-=2; if((*SP).data.o != SP[1].data.o) /* IF_ACMPNE */ ");
break;
case Opcodes.GOTO:
// this space intentionally left blank
break;
case Opcodes.JSR:
b.append("/* JSR TODO */");
/*b.append("PUSH_")
b.append("goto label_");
b.append(label.toString());
b.append(";\n");
b.append("JSR_RETURN_LABEL_");
b.append(jsrCounter);
b.append(":");
jsrCounter++;*/
return;
case Opcodes.IFNULL:
b.append("if(POP_OBJ() == JAVA_NULL) /* IFNULL */ ");
break;
case Opcodes.IFNONNULL:
b.append("if(POP_OBJ() != JAVA_NULL) /* IFNONNULL */ ");
break;
}
if(TryCatch.isTryCatchInMethod()) {
b.append("JUMP_TO(label_");
b.append(label.toString());
b.append(", ");
b.append(LabelInstruction.getLabelCatchDepth(label, instructions));
b.append(");\n");
} else {
b.append("goto label_");
b.append(label.toString());
b.append(";\n");
}
}
/**
* Returns a conditional return that returns on an {@code int} value of {@code 0}.
*
* @return A conditional return that returns on an {@code int} value of {@code 0}.
*/
protected static ConditionalReturn onZeroInteger() {
return new ConditionalReturn(Opcodes.IFNE);
}