Example usage for org.objectweb.asm Opcodes T_DOUBLE

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

Introduction

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

Prototype

int T_DOUBLE

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

Click Source Link

Usage

From source file:com.offbynull.coroutines.instrumenter.OperandStackStateGenerators.java

License:Open Source License

/**
 * Generates instructions to save a certain number of items from the top of the operand stack.
 * <p>/*www.  java 2s .  c o  m*/
 * The instructions generated here expect the operand stack to be fully loaded. The stack items specified by {@code frame} must actually
 * all be on the operand stack.
 * <p>
 * REMEMBER: The items aren't returned to the operand stack after they've been saved (they have been popped off the stack). If you want
 * them back on the operand stack, reload using
 * {@code loadOperandStack(markerType, storageVars, frame, frame.getStackSize() - count, frame.getStackSize() - count, count)}.
 * @param markerType debug marker type
 * @param storageVars variables to store operand stack in to
 * @param frame execution frame at the instruction where the operand stack is to be saved
 * @param count number of items to store from the stack
 * @return instructions to save the operand stack to the storage variables
 * @throws NullPointerException if any argument is {@code null}
 * @throws IllegalArgumentException if {@code size} is larger than the number of items in the stack at {@code frame} (or is negative),
 * or if {@code count} is larger than {@code top} (or is negative)
 */
public static InsnList saveOperandStack(MarkerType markerType, StorageVariables storageVars,
        Frame<BasicValue> frame, int count) {
    Validate.notNull(markerType);
    Validate.notNull(storageVars);
    Validate.notNull(frame);
    Validate.isTrue(count >= 0);
    Validate.isTrue(count <= frame.getStackSize());

    Variable intsVar = storageVars.getIntStorageVar();
    Variable floatsVar = storageVars.getFloatStorageVar();
    Variable longsVar = storageVars.getLongStorageVar();
    Variable doublesVar = storageVars.getDoubleStorageVar();
    Variable objectsVar = storageVars.getObjectStorageVar();

    StorageSizes storageSizes = computeSizes(frame, frame.getStackSize() - count, count);

    int intsCounter = storageSizes.getIntsSize() - 1;
    int floatsCounter = storageSizes.getFloatsSize() - 1;
    int longsCounter = storageSizes.getLongsSize() - 1;
    int doublesCounter = storageSizes.getDoublesSize() - 1;
    int objectsCounter = storageSizes.getObjectsSize() - 1;

    InsnList ret = new InsnList();

    // Create stack storage arrays and save them
    ret.add(merge(debugMarker(markerType, "Saving operand stack (" + count + " items)"),
            mergeIf(storageSizes.getIntsSize() > 0, () -> new Object[] {
                    debugMarker(markerType, "Generating ints container (" + storageSizes.getIntsSize() + ")"),
                    new LdcInsnNode(storageSizes.getIntsSize()),
                    new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT),
                    new VarInsnNode(Opcodes.ASTORE, intsVar.getIndex()) }),
            mergeIf(storageSizes.getFloatsSize() > 0,
                    () -> new Object[] {
                            debugMarker(markerType,
                                    "Generating floats container (" + storageSizes.getFloatsSize() + ")"),
                            new LdcInsnNode(storageSizes.getFloatsSize()),
                            new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_FLOAT),
                            new VarInsnNode(Opcodes.ASTORE, floatsVar.getIndex()) }),
            mergeIf(storageSizes.getLongsSize() > 0, () -> new Object[] {
                    debugMarker(markerType, "Generating longs container (" + storageSizes.getLongsSize() + ")"),
                    new LdcInsnNode(storageSizes.getLongsSize()),
                    new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_LONG),
                    new VarInsnNode(Opcodes.ASTORE, longsVar.getIndex()) }),
            mergeIf(storageSizes.getDoublesSize() > 0, () -> new Object[] {
                    debugMarker(markerType,
                            "Generating doubles container (" + storageSizes.getDoublesSize() + ")"),
                    new LdcInsnNode(storageSizes.getDoublesSize()),
                    new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_DOUBLE),
                    new VarInsnNode(Opcodes.ASTORE, doublesVar.getIndex()) }),
            mergeIf(storageSizes.getObjectsSize() > 0,
                    () -> new Object[] {
                            debugMarker(markerType,
                                    "Generating objects container (" + storageSizes.getObjectsSize() + ")"),
                            new LdcInsnNode(storageSizes.getObjectsSize()),
                            new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"),
                            new VarInsnNode(Opcodes.ASTORE, objectsVar.getIndex()) })));

    // Save the stack
    int start = frame.getStackSize() - 1;
    int end = frame.getStackSize() - count;
    for (int i = start; i >= end; i--) {
        BasicValue basicValue = frame.getStack(i);
        Type type = basicValue.getType();

        // If type is 'Lnull;', this means that the slot has been assigned null and that "there has been no merge yet that would 'raise'
        // the type toward some class or interface type" (from ASM mailing list). We know this slot will always contain null at this
        // point in the code so we can avoid saving it (but we still need to do a POP to get rid of it). When we load it back up, we can
        // simply push a null in to that slot, thereby keeping the same 'Lnull;' type.
        if ("Lnull;".equals(type.getDescriptor())) {
            ret.add(debugMarker(markerType, "Skipping null value at " + i));
            ret.add(new InsnNode(Opcodes.POP));
            continue;
        }

        // Convert the item to an object (if not already an object) and stores it in local vars table. Item removed from stack.
        switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.BYTE:
        case Type.SHORT:
        case Type.CHAR:
        case Type.INT:
            ret.add(debugMarker(markerType,
                    "Popping/storing int at " + i + " to storage index " + intsCounter));
            ret.add(new VarInsnNode(Opcodes.ALOAD, intsVar.getIndex())); // [val, int[]]
            ret.add(new InsnNode(Opcodes.SWAP)); // [int[], val]
            ret.add(new LdcInsnNode(intsCounter)); // [int[], val, idx]
            ret.add(new InsnNode(Opcodes.SWAP)); // [int[], idx, val]
            ret.add(new InsnNode(Opcodes.IASTORE)); // []
            intsCounter--;
            break;
        case Type.FLOAT:
            ret.add(debugMarker(markerType,
                    "Popping/storing float at " + i + " to storage index " + floatsCounter));
            ret.add(new VarInsnNode(Opcodes.ALOAD, floatsVar.getIndex())); // [val, float[]]
            ret.add(new InsnNode(Opcodes.SWAP)); // [float[], val]
            ret.add(new LdcInsnNode(floatsCounter)); // [float[], val, idx]
            ret.add(new InsnNode(Opcodes.SWAP)); // [float[], idx, val]
            ret.add(new InsnNode(Opcodes.FASTORE)); // []
            floatsCounter--;
            break;
        case Type.LONG:
            ret.add(debugMarker(markerType,
                    "Popping/storing long at " + i + " to storage index " + longsCounter));
            ret.add(new VarInsnNode(Opcodes.ALOAD, longsVar.getIndex())); // [val_PART1, val_PART2, long[]]
            ret.add(new LdcInsnNode(longsCounter)); // [val_PART1, val_PART2, long[], idx]
            ret.add(new InsnNode(Opcodes.DUP2_X2)); // [long[], idx, val_PART1, val_PART2, long[], idx]
            ret.add(new InsnNode(Opcodes.POP2)); // [long[], idx, val_PART1, val_PART2]
            ret.add(new InsnNode(Opcodes.LASTORE)); // []
            longsCounter--;
            break;
        case Type.DOUBLE:
            ret.add(debugMarker(markerType,
                    "Popping/storing double at " + i + " to storage index " + doublesCounter));
            ret.add(new VarInsnNode(Opcodes.ALOAD, doublesVar.getIndex())); // [val_PART1, val_PART2, double[]]
            ret.add(new LdcInsnNode(doublesCounter)); // [val_PART1, val_PART2, double[], idx]
            ret.add(new InsnNode(Opcodes.DUP2_X2)); // [double[], idx, val_PART1, val_PART2, double[], idx]
            ret.add(new InsnNode(Opcodes.POP2)); // [double[], idx, val_PART1, val_PART2]
            ret.add(new InsnNode(Opcodes.DASTORE)); // []
            doublesCounter--;
            break;
        case Type.ARRAY:
        case Type.OBJECT:
            ret.add(debugMarker(markerType,
                    "Popping/storing object at " + i + " to storage index " + objectsCounter));
            ret.add(new VarInsnNode(Opcodes.ALOAD, objectsVar.getIndex())); // [val, object[]]
            ret.add(new InsnNode(Opcodes.SWAP)); // [object[], val]
            ret.add(new LdcInsnNode(objectsCounter)); // [object[], val, idx]
            ret.add(new InsnNode(Opcodes.SWAP)); // [object[], idx, val]
            ret.add(new InsnNode(Opcodes.AASTORE)); // []
            objectsCounter--;
            break;
        case Type.METHOD:
        case Type.VOID:
        default:
            throw new IllegalArgumentException();
        }
    }

    // At this point, the storage array will contain the saved operand stack AND THE STACK WILL HAVE count ITEMS POPPED OFF OF IT.
    // 
    // Reload using...
    // ---------------
    // ret.add(debugMarker(markerType, "Reloading stack items"));
    // InsnList reloadInsnList = loadOperandStack(markerType, storageVars, frame,
    //         frame.getStackSize() - count,
    //         frame.getStackSize() - count,
    //         count);
    // ret.add(reloadInsnList);

    return ret;
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public void emitNewArray(TypeWidget elementType, BytecodeExpression e) {
    MethodVisitor mv = getMethodVisitor();
    exec(e);//from   w w w  .  j a  v a 2s .  c o  m
    cast(BaseTypeAdapter.INT32, e.getType());
    switch (elementType.getJVMType().getSort()) {
    case Type.BYTE:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_BYTE);
        break;
    case Type.BOOLEAN:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_BOOLEAN);
        break;
    case Type.SHORT:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_SHORT);
        break;
    case Type.INT:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT);
        break;
    case Type.CHAR:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_CHAR);
        break;
    case Type.FLOAT:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_FLOAT);
        break;
    case Type.LONG:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_LONG);
        break;
    case Type.DOUBLE:
        mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_DOUBLE);
        break;
    case Type.OBJECT:
        mv.visitTypeInsn(Opcodes.ANEWARRAY, elementType.getJVMType().getInternalName());
        break;
    default:
        throw new UnsupportedOperationException("unknown sort for newArray" + elementType.getJVMType());
    }

}

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

License:Open Source License

private int getSort(final Type type) {
    final int sort = type.getSort();
    switch (sort) {
    case Type.INT:
        return Opcodes.T_INT;
    case Type.FLOAT:
        return Opcodes.T_FLOAT;
    case Type.LONG:
        return Opcodes.T_LONG;
    case Type.DOUBLE:
        return Opcodes.T_DOUBLE;
    case Type.SHORT:
        return Opcodes.T_SHORT;
    case Type.CHAR:
        return Opcodes.T_CHAR;
    case Type.BOOLEAN:
        return Opcodes.T_BOOLEAN;
    case Type.BYTE:
        return Opcodes.T_BYTE;
    default:// ww w.  j  a v  a2 s .  co  m
        return -1;
    }
}

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

License:Open Source License

private Type getObjectType(final int operand) {
    if (Opcodes.T_INT == operand) {
        return Type.getType(int[].class);
    }/*from  w  w w . j a v  a2s . co m*/
    if (Opcodes.T_FLOAT == operand) {
        return Type.getType(float[].class);
    }
    if (Opcodes.T_LONG == operand) {
        return Type.getType(long[].class);
    }
    if (Opcodes.T_DOUBLE == operand) {
        return Type.getType(double[].class);
    }
    return Type.getType(Object.class);
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.FinalFieldInlinerTest.java

License:Open Source License

/**
 * Tests that finalFieldInliner is is working correctly for field-Chains with mutli-arrays.
 * /*ww w .j a  v  a2  s  . c o  m*/
 * @throws Exception
 *           the exception
 */
@Test
public void testFinalFieldInlinerFieldChainMultiArray() throws Exception {
    // INIT
    final ClassNodeBuilder builderC = ClassNodeBuilder.createClass("de.tuberlin.uebb.jbop.optimizer.var.CM")
            .addField("d", "[[D").withModifiers(ACC_PRIVATE, ACC_FINAL).withAnnotation(ImmutableArray.class)
            .addToConstructor(new VarInsnNode(ALOAD, 0)).//
            addToConstructor(new InsnNode(ICONST_1)).//
            addToConstructor(new TypeInsnNode(ANEWARRAY, "[D")).//
            addToConstructor(new InsnNode(DUP)).//
            addToConstructor(new InsnNode(ICONST_0)).//
            addToConstructor(new InsnNode(ICONST_1)).//
            addToConstructor(new IntInsnNode(NEWARRAY, Opcodes.T_DOUBLE)).//
            addToConstructor(new InsnNode(DUP)).//
            addToConstructor(new InsnNode(ICONST_0)).//
            addToConstructor(new InsnNode(DCONST_1)).//
            addToConstructor(new InsnNode(DASTORE)).//
            addToConstructor(new InsnNode(AASTORE)).//
            addToConstructor(new FieldInsnNode(PUTFIELD, "de/tuberlin/uebb/jbop/optimizer/var/CM", "d", "[[D")).//
            toClass();
    final ClassNodeBuilder builderB = ClassNodeBuilder.createClass("de.tuberlin.uebb.jbop.optimizer.var.BM")
            .addField("c", Type.getDescriptor(builderC.getBuildedClass())).withModifiers(ACC_PRIVATE, ACC_FINAL)
            .initWith(null).toClass();
    final ClassNodeBuilder builderA = ClassNodeBuilder.createClass("de.tuberlin.uebb.jbop.optimizer.var.AM")
            .addField("b", Type.getDescriptor(builderB.getBuildedClass())).withModifiers(ACC_PRIVATE, ACC_FINAL)
            .initWith(null).toClass();
    final ClassNodeBuilder builderTestClass = ClassNodeBuilder
            .createClass("de.tuberlin.uebb.jbop.optimizer.var.ChainedTestClassM")
            .addField("a", Type.getDescriptor(builderA.getBuildedClass())).withModifiers(ACC_PRIVATE, ACC_FINAL)
            .initWith(null).//
            addMethod("get", "()D").//
            addGetClassField("a").// ;
            addGetField(builderA, "b").//
            addGetField(builderB, "c").//
            addGetField(builderC, "d").//
            addInsn(new InsnNode(ICONST_0)).//
            addInsn(new InsnNode(AALOAD)).//
            addInsn(new InsnNode(ICONST_0)).//
            addInsn(new InsnNode(DALOAD)).//
            addInsn(new InsnNode(DRETURN));//

    // RUN
    final Object instance = builderTestClass.instance();

    inliner.setInputObject(instance);
    method = builderTestClass.getMethod("get");
    final InsnList optimized = inliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(2, optimized.size());
    assertEquals(1.0, NodeHelper.getNumberValue(optimized.get(0)).doubleValue(), .00001);
}

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

License:Open Source License

public NewArrayInstruction(final ReadMethod readMethod, final int lineNumber, final int arrayElemType,
        int newObjIdSeqIndex) {
    super(readMethod, Opcodes.NEWARRAY, lineNumber);
    assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR
            || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE
            || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT
            || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG;
    this.arrayElemType = arrayElemType;
    this.newObjectIdentifierSequenceIndex = newObjIdSeqIndex;
}

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

License:Open Source License

private NewArrayInstruction(final ReadMethod readMethod, final int lineNumber, final int arrayElemType,
        final int index, int newObjIdSeqIndex) {
    super(readMethod, Opcodes.NEWARRAY, lineNumber, index);
    assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR
            || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE
            || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT
            || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG;
    this.arrayElemType = arrayElemType;
    this.newObjectIdentifierSequenceIndex = newObjIdSeqIndex;
}

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

License:Open Source License

@Override
public String toString() {
    String elemType;/*from ww w .  java2s.co m*/
    switch (this.arrayElemType) {
    case Opcodes.T_BOOLEAN:
        elemType = "T_BOOLEAN";
        break;
    case Opcodes.T_CHAR:
        elemType = "T_CHAR";
        break;
    case Opcodes.T_FLOAT:
        elemType = "T_FLOAT";
        break;
    case Opcodes.T_DOUBLE:
        elemType = "T_DOUBLE";
        break;
    case Opcodes.T_BYTE:
        elemType = "T_BYTE";
        break;
    case Opcodes.T_SHORT:
        elemType = "T_SHORT";
        break;
    case Opcodes.T_INT:
        elemType = "T_INT";
        break;
    case Opcodes.T_LONG:
        elemType = "T_LONG";
        break;
    default:
        elemType = "--ERROR--";
    }
    return new StringBuilder(elemType.length() + 9).append("NEWARRAY ").append(elemType).toString();
}

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

License:Open Source License

public NewArrayInstruction2(final ReadMethod readMethod, final int lineNumber, final int arrayElemType,
        long newObjIdSeqIndex) {
    super(readMethod, Opcodes.NEWARRAY, lineNumber);
    assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR
            || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE
            || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT
            || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG;
    this.arrayElemType = arrayElemType;
    this.newObjectIdentifier = newObjIdSeqIndex;
}

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

License:Open Source License

public NewArrayInstruction2(final ReadMethod readMethod, final int lineNumber, final int arrayElemType,
        final int index, long newObjIdSeqIndex) {
    super(readMethod, Opcodes.NEWARRAY, lineNumber, index);
    assert arrayElemType == Opcodes.T_BOOLEAN || arrayElemType == Opcodes.T_CHAR
            || arrayElemType == Opcodes.T_FLOAT || arrayElemType == Opcodes.T_DOUBLE
            || arrayElemType == Opcodes.T_BYTE || arrayElemType == Opcodes.T_SHORT
            || arrayElemType == Opcodes.T_INT || arrayElemType == Opcodes.T_LONG;
    this.arrayElemType = arrayElemType;
    this.newObjectIdentifier = newObjIdSeqIndex;
}