Example usage for org.objectweb.asm Opcodes NEW

List of usage examples for org.objectweb.asm Opcodes NEW

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes NEW.

Prototype

int NEW

To view the source code for org.objectweb.asm Opcodes NEW.

Click Source Link

Usage

From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java

License:Open Source License

/**
 * Objects that are not parameters and not written before
 * these can be:/* w w w.j  av a  2 s  .co  m*/
 * getField
 * getStatic
 * new
 * new array
 * new multi array
 * return type of method call
 */
private Type resolveType(final AbstractInsnNode node) {
    int arrayCount = 0;
    AbstractInsnNode currentNode = NodeHelper.getPrevious(node);
    while (currentNode != null) {
        final int opcode2 = currentNode.getOpcode();
        if (opcode2 == Opcodes.NEWARRAY) {
            final int operand = ((IntInsnNode) currentNode).operand;
            return getObjectType(operand);
        } else if (opcode2 == Opcodes.ANEWARRAY) {
            return getObjectType(((TypeInsnNode) currentNode).desc);
        } else if (opcode2 == Opcodes.MULTIANEWARRAY) {
            return getObjectType(((MultiANewArrayInsnNode) currentNode).desc);
        } else if (opcode2 == Opcodes.NEW) {
            final String desc = ((TypeInsnNode) currentNode).desc;
            return getObjectType(desc);
        } else if ((opcode2 >= Opcodes.IALOAD) && (opcode2 <= Opcodes.AALOAD)) {
            arrayCount++;
        } else if ((opcode2 == Opcodes.GETFIELD) || (opcode2 == Opcodes.GETSTATIC)) {
            final String desc = ((FieldInsnNode) currentNode).desc;
            return getObjectType(removeArrayType(desc, arrayCount));
        } else if ((opcode2 == Opcodes.ALOAD)) {
            final Type type2 = readers.getFirstVar(((VarInsnNode) currentNode).var).getParameterType();
            return getObjectType(removeArrayType(type2.getDescriptor(), arrayCount));
        } else if ((opcode2 >= Opcodes.INVOKEVIRTUAL) && (opcode2 <= Opcodes.INVOKEDYNAMIC)) {
            return Type.getReturnType(((MethodInsnNode) currentNode).desc);
        }
        currentNode = NodeHelper.getPrevious(currentNode);
    }
    return Type.VOID_TYPE;
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.removeSystemExit.RemoveSystemExitMethodAdapter.java

License:Open Source License

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
    if (name.equals("exita") && owner.equals("java/lang/System")) {
        logger.info("Replacing System.exit ");

        Label mutationStartLabel = new Label();
        mutationStartLabel.info = new MutationMarker(true);
        mv.visitLabel(mutationStartLabel);

        mv.visitInsn(Opcodes.POP);/*from  ww w.  j a  va 2s.  c o  m*/
        mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException");
        mv.visitInsn(Opcodes.DUP);
        mv.visitLdcInsn("Replaced System Exit");
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                "(Ljava/lang/String;)V");
        mv.visitInsn(Opcodes.ATHROW);

        Label mutationEndLabel = new Label();
        mutationEndLabel.info = new MutationMarker(false);
        mv.visitLabel(mutationEndLabel);

    } else {
        super.visitMethodInsn(opcode, owner, name, desc);
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.removeSystemExit.RemoveSystemExitMethodNode.java

License:Open Source License

@SuppressWarnings("unchecked")
// Call to pre-1.5 Code
@Override/*from ww w . j  av a2 s . c  o m*/
public void visitEnd() {
    MethodNode mn = (MethodNode) mv;
    InsnList insns = mn.instructions;
    Iterator i = insns.iterator();
    AbstractInsnNode prev = null;
    InsnList newInstrucionList = new InsnList();
    while (i.hasNext()) {
        boolean addInstruction = true;
        AbstractInsnNode i1 = (AbstractInsnNode) i.next();
        if (i1 instanceof MethodInsnNode) {
            MethodInsnNode methotInsnNode = (MethodInsnNode) i1;
            if (methotInsnNode.name.equals("exit") && methotInsnNode.owner.equals("java/lang/System")) {
                logger.info("Replacing System.exit ");
                newInstrucionList.remove(prev);
                // insns.remove(i1);
                InsnList il = new InsnList();
                Label mutationStartLabel = new Label();
                mutationStartLabel.info = new MutationMarker(true);

                il.add(new LabelNode(mutationStartLabel));
                il.add(new TypeInsnNode(Opcodes.NEW, "java/lang/RuntimeException"));
                il.add(new InsnNode(Opcodes.DUP));
                il.add(new LdcInsnNode("Replaced System.exit()"));
                il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                        "(Ljava/lang/String;)V"));
                il.add(new InsnNode(Opcodes.ATHROW));

                Label mutationEndLabel = new Label();
                mutationEndLabel.info = new MutationMarker(false);
                il.add(new LabelNode(mutationEndLabel));
                newInstrucionList.add(il);
                addInstruction = false;
            }
        }
        if (addInstruction) {
            try {
                insns.remove(i1);
                newInstrucionList.add(i1);
            } catch (Exception e) {
                logger.error(e);
            }

        }
        prev = i1;
    }
    mn.instructions = newInstrucionList;
    mn.accept(next);
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

public TypeInstruction(final ReadMethod readMethod, final int opcode, final int lineNumber,
        final String className, int newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = className;
    this.newObjectIdentifierSeqIndex = newObjIdSeqIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

private TypeInstruction(final ReadMethod readMethod, final int lineNumber, final int opcode,
        final String typeDesc, final int index, int newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber, index);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = typeDesc;
    this.newObjectIdentifierSeqIndex = newObjIdSeqIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

@Override
public void writeOut(final DataOutputStream out, final StringCacheOutput stringCache) throws IOException {
    super.writeOut(out, stringCache);
    stringCache.writeString(this.className, out);
    if (getOpcode() == Opcodes.NEW || getOpcode() == Opcodes.ANEWARRAY)
        OptimizedDataOutputStream.writeInt0(this.newObjectIdentifierSeqIndex, out);
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

public static TypeInstruction readFrom(final DataInputStream in, final MethodReadInformation methodInfo,
        final StringCacheInput stringCache, final int opcode, final int index, final int lineNumber)
        throws IOException {
    final String type = stringCache.readString(in);
    int newObjIdSeqIndex = opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY
            ? OptimizedDataInputStream.readInt0(in)
            : -1;/*from w ww. ja  va  2 s .c o m*/
    return new TypeInstruction(methodInfo.getMethod(), lineNumber, opcode, type, index, newObjIdSeqIndex);
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction.java

License:Open Source License

@Override
public String toString() {
    String instruction;/*from ww w.  ja v  a2  s  .co m*/
    switch (getOpcode()) {
    case Opcodes.NEW:
        instruction = "NEW";
        break;
    case Opcodes.ANEWARRAY:
        instruction = "ANEWARRAY";
        break;
    case Opcodes.CHECKCAST:
        instruction = "CHECKCAST";
        break;
    case Opcodes.INSTANCEOF:
        instruction = "INSTANCEOF";
        break;
    default:
        instruction = "-ERROR-";
    }
    return new StringBuilder(instruction.length() + this.className.length() + 1).append(instruction).append(' ')
            .append(this.className).toString();
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction2.java

License:Open Source License

public TypeInstruction2(final ReadMethod readMethod, final int opcode, final int lineNumber,
        final String className, long newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = className;
    this.newObjectIdentifier = newObjIdSeqIndex;
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.TypeInstruction2.java

License:Open Source License

public TypeInstruction2(final ReadMethod readMethod, final int lineNumber, final int opcode,
        final String typeDesc, final int index, long newObjIdSeqIndex) {
    super(readMethod, opcode, lineNumber, index);
    assert opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY || opcode == Opcodes.CHECKCAST
            || opcode == Opcodes.INSTANCEOF;
    assert ((opcode == Opcodes.CHECKCAST || opcode == Opcodes.INSTANCEOF) && newObjIdSeqIndex == -1)
            || ((opcode == Opcodes.NEW || opcode == Opcodes.ANEWARRAY) && newObjIdSeqIndex != -1);
    this.className = typeDesc;
    this.newObjectIdentifier = newObjIdSeqIndex;
}