Example usage for org.objectweb.asm Opcodes ANEWARRAY

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

Introduction

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

Prototype

int ANEWARRAY

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

Click Source Link

Usage

From source file:de.tuberlin.uebb.jbop.optimizer.ClassNodeBuilder.java

License:Open Source License

/**
 * Adds the array to the last created method.
 * // w  w  w.  j  a v a2  s . co m
 * @param desc
 *          the desc
 * @param length
 *          the length
 * @return the class node builder
 */
public ClassNodeBuilder addArray(final String desc, final int... length) {
    if (isInterface) {
        return this;
    }
    final Type elementType = Type.getType(desc).getElementType();
    if (length.length == 1) {

        addInsn(NodeHelper.getInsnNodeFor(Integer.valueOf(length[0])));
        if (elementType.getDescriptor().startsWith("L")) {
            addInsn(new TypeInsnNode(Opcodes.ANEWARRAY, elementType.getInternalName()));
        } else {
            addInsn(new IntInsnNode(Opcodes.NEWARRAY, getSort(elementType)));
        }
    } else {
        for (final int currentLength : length) {
            addInsn(NodeHelper.getInsnNodeFor(Integer.valueOf(currentLength)));
        }
        addInsn(new MultiANewArrayInsnNode(desc, length.length));
    }
    addInsn(new VarInsnNode(Opcodes.ASTORE, methodVarIndex));
    lastMethodVarIndex = methodVarIndex;
    lastVarElementType = elementType;
    methodVarIndex++;
    return this;
}

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://from  ww w .  j a va2s  .  c  om
 * 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.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;/*  w ww .  j a v a 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 w  w  w.  j  av  a 2  s  .  c  o  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;
}

From source file:de.unisb.cs.st.javaslicer.instructionSimulation.Simulator.java

License:Open Source License

private DynamicInformation simulateTypeInsn(InstructionInstance inst, SimulationEnvironment simEnv) {
    assert inst.getInstruction().getType() == InstructionType.TYPE;
    TypeInstrInstanceInfo info = (TypeInstrInstanceInfo) inst.getAdditionalInfo();
    int stackDepth = inst.getStackDepth();
    switch (inst.getInstruction().getOpcode()) {
    case Opcodes.NEW:
        return new SimpleVariableUsage(DynamicInformation.EMPTY_VARIABLE_SET,
                Collections.<Variable>singleton(
                        simEnv.getOpStackEntry(stackDepth, simEnv.decAndGetOpStack(stackDepth))),
                Collections.<Long, Collection<? extends Variable>>singletonMap(info.getNewObjectIdentifier(),
                        getAllFields(((TypeInstruction) inst.getInstruction()).getJavaClassName(),
                                info.getNewObjectIdentifier())));
    case Opcodes.ANEWARRAY:
        int stackSize = simEnv.getOpStack(stackDepth) - 1;
        IntHolder h = this.maxArrayElem.remove(info.getNewObjectIdentifier());
        Collection<Variable> stackEntryColl = Collections
                .<Variable>singleton(simEnv.getOpStackEntry(stackDepth, stackSize));
        return new SimpleVariableUsage(stackEntryColl, stackEntryColl,
                Collections.<Long, Collection<? extends Variable>>singletonMap(info.getNewObjectIdentifier(),
                        new ArrayElementsList(h == null ? 0 : (h.get() + 1), info.getNewObjectIdentifier())));
    case Opcodes.CHECKCAST:
        return new SimpleVariableUsage(simEnv.getOpStackEntry(stackDepth, simEnv.getOpStack(stackDepth) - 1),
                DynamicInformation.EMPTY_VARIABLE_SET);
    case Opcodes.INSTANCEOF:
        return stackManipulation(simEnv, stackDepth, 1, 1);
    default:/*  ww  w . j  ava  2 s .c om*/
        assert false;
        return null;
    }
}