Example usage for org.objectweb.asm Opcodes DSTORE

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

Introduction

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

Prototype

int DSTORE

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

Click Source Link

Usage

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void store(Value v, InsnList insns) {
    assert registers.containsKey(v) : v;
    int reg = registers.get(v);
    Type t = v instanceof LocalVariable ? ((LocalVariable) v).getType().getFieldType() : v.getType();
    if (t instanceof ReferenceType || t instanceof NullType)
        insns.add(new VarInsnNode(Opcodes.ASTORE, reg));
    else if (t.equals(longType))
        insns.add(new VarInsnNode(Opcodes.LSTORE, reg));
    else if (t.equals(floatType))
        insns.add(new VarInsnNode(Opcodes.FSTORE, reg));
    else if (t.equals(doubleType))
        insns.add(new VarInsnNode(Opcodes.DSTORE, reg));
    else if (t.isSubtypeOf(intType))
        insns.add(new VarInsnNode(Opcodes.ISTORE, reg));
    else//  ww  w. j  a  v  a2 s. co m
        throw new AssertionError("unstorable value: " + v);
}

From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java

License:Open Source License

private static int storeOpcode(Class cls) {
    if (cls.equals(Void.TYPE))
        throw new IllegalArgumentException("can not load void");

    int storecode;
    if (cls.equals(Boolean.TYPE))
        storecode = Opcodes.ISTORE;//from   ww  w .j  a va  2  s.  com
    else if (cls.equals(Byte.TYPE))
        storecode = Opcodes.ISTORE;
    else if (cls.equals(Character.TYPE))
        storecode = Opcodes.ISTORE;
    else if (cls.equals(Short.TYPE))
        storecode = Opcodes.ISTORE;
    else if (cls.equals(Integer.TYPE))
        storecode = Opcodes.ISTORE;
    else if (cls.equals(Long.TYPE))
        storecode = Opcodes.LSTORE;
    else if (cls.equals(Float.TYPE))
        storecode = Opcodes.FSTORE;
    else if (cls.equals(Double.TYPE))
        storecode = Opcodes.DSTORE;
    else
        storecode = Opcodes.ASTORE;

    return storecode;
}

From source file:jp.co.dgic.testing.common.virtualmock.asm.AbstractAsmMethodVisitor.java

License:Open Source License

protected int getStoreOpcodeByType(Type type) {
    if (type.equals(Type.BOOLEAN_TYPE))
        return Opcodes.ISTORE;
    if (type.equals(Type.BYTE_TYPE))
        return Opcodes.ISTORE;
    if (type.equals(Type.CHAR_TYPE))
        return Opcodes.ISTORE;
    if (type.equals(Type.SHORT_TYPE))
        return Opcodes.ISTORE;
    if (type.equals(Type.INT_TYPE))
        return Opcodes.ISTORE;
    if (type.equals(Type.LONG_TYPE))
        return Opcodes.LSTORE;
    if (type.equals(Type.DOUBLE_TYPE))
        return Opcodes.DSTORE;
    if (type.equals(Type.FLOAT_TYPE))
        return Opcodes.FSTORE;
    return Opcodes.ASTORE;
}

From source file:lucee.transformer.bytecode.statement.tag.TagLoop.java

License:Open Source License

/**
 * write out index loop//from   ww  w .ja  v a 2 s . c  o  m
 * @param adapter
 * @throws TemplateException
 */
private void writeOutTypeFromTo(BytecodeContext bc) throws BytecodeException {
    ForDoubleVisitor forDoubleVisitor = new ForDoubleVisitor();
    loopVisitor = forDoubleVisitor;
    GeneratorAdapter adapter = bc.getAdapter();

    // int from=(int)@from;
    int from = adapter.newLocal(Types.DOUBLE_VALUE);
    ExpressionUtil.writeOutSilent(getAttribute("from").getValue(), bc, Expression.MODE_VALUE);
    adapter.storeLocal(from);

    // int to=(int)@to;
    int to = adapter.newLocal(Types.DOUBLE_VALUE);
    ExpressionUtil.writeOutSilent(getAttribute("to").getValue(), bc, Expression.MODE_VALUE);
    adapter.storeLocal(to);

    // int step=(int)@step;
    int step = adapter.newLocal(Types.DOUBLE_VALUE);
    Attribute attrStep = getAttribute("step");
    if (attrStep != null) {
        ExpressionUtil.writeOutSilent(attrStep.getValue(), bc, Expression.MODE_VALUE);
    } else {
        adapter.push(1D);
    }
    adapter.storeLocal(step);

    // boolean dirPlus=(step > 0);
    int dirPlus = adapter.newLocal(Types.BOOLEAN_VALUE);
    DecisionDoubleVisitor div = new DecisionDoubleVisitor();
    div.visitBegin();
    adapter.loadLocal(step);
    div.visitGT();
    adapter.push(0D);
    div.visitEnd(bc);
    adapter.storeLocal(dirPlus);

    //if(step!=0) {
    div = new DecisionDoubleVisitor();
    div.visitBegin();
    adapter.loadLocal(step);
    div.visitNEQ();
    adapter.push(0D);
    div.visitEnd(bc);
    Label ifEnd = new Label();
    adapter.ifZCmp(Opcodes.IFEQ, ifEnd);

    // VariableReference index>=VariableInterpreter.getVariableReference(pc,@index));
    int index = adapter.newLocal(Types.VARIABLE_REFERENCE);
    adapter.loadArg(0);
    Attribute attr = getAttribute("index");
    if (attr == null)
        attr = getAttribute("item");
    ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
    adapter.storeLocal(index);

    // index.set(from);
    adapter.loadLocal(index);
    adapter.loadLocal(from);
    adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE);

    // for

    //int i=forConditionVisitor.visitBeforeExpression(adapter,from,step,true);

    // init
    adapter.visitLabel(forDoubleVisitor.beforeInit);
    forDoubleVisitor.forInit(adapter, from, true);
    adapter.goTo(forDoubleVisitor.beforeExpr);

    // update
    adapter.visitLabel(forDoubleVisitor.beforeUpdate);
    adapter.loadLocal(index);
    //forConditionVisitor.forUpdate(adapter, step, true);
    adapter.visitVarInsn(Opcodes.DLOAD, forDoubleVisitor.i);
    adapter.loadLocal(step);
    adapter.visitInsn(Opcodes.DADD);
    adapter.visitInsn(Opcodes.DUP2);
    adapter.visitVarInsn(Opcodes.DSTORE, forDoubleVisitor.i);

    adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE);

    // expression
    adapter.visitLabel(forDoubleVisitor.beforeExpr);
    int i = forDoubleVisitor.i;

    adapter.loadLocal(dirPlus);
    Label l1 = new Label();
    adapter.visitJumpInsn(Opcodes.IFEQ, l1);

    div = new DecisionDoubleVisitor();
    div.visitBegin();
    adapter.visitVarInsn(Opcodes.DLOAD, i);
    div.visitLTE();
    adapter.loadLocal(to);
    div.visitEnd(bc);

    Label l2 = new Label();
    adapter.visitJumpInsn(Opcodes.GOTO, l2);
    adapter.visitLabel(l1);

    div = new DecisionDoubleVisitor();
    div.visitBegin();
    adapter.visitVarInsn(Opcodes.DLOAD, i);
    div.visitGTE();
    adapter.loadLocal(to);
    div.visitEnd(bc);

    adapter.visitLabel(l2);
    forDoubleVisitor.visitAfterExpressionBeginBody(adapter);

    //adapter.loadLocal(index);
    //adapter.visitVarInsn(Opcodes.DLOAD, i);
    //adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE);

    getBody().writeOut(bc);

    forDoubleVisitor.visitEndBody(bc, getEnd());

    ////// set i after usage
    //adapter.loadLocal(index);
    //adapter.visitVarInsn(Opcodes.DLOAD, i);
    //adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE);

    adapter.visitLabel(ifEnd);

}

From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java

License:Apache License

public void visitVarInsn(int opcode, int var) {
    String description = (var == 0 ? "this" : "v" + var);
    switch (opcode) {
    case Opcodes.ISTORE:
    case Opcodes.LSTORE:
    case Opcodes.FSTORE:
    case Opcodes.DSTORE:
    case Opcodes.ASTORE: {
        Type type = getType(Opcodes.ISTORE, opcode);
        pop(type);//from w  w w .ja  v a2  s. co  m
    }
        break;
    case Opcodes.ILOAD:
    case Opcodes.LLOAD:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
    case Opcodes.ALOAD: {
        Type type = getType(Opcodes.ILOAD, opcode);
        if (_isStatic) {
            var++;
        }
        if (var == 0) {
            type = _this;
        } else if (var <= _arguments.length) {
            type = _arguments[var - 1];
        }
        push(description, type);
    }
        break;
    default:
        throw new IllegalArgumentException("Unsupported opcode " + OPCODES[opcode]);
    }
    print(opcode, description);
}

From source file:org.apache.drill.exec.compile.bytecode.ValueHolderIden.java

License:Apache License

private static void initType(int index, Type t, DirectSorter v) {
    switch (t.getSort()) {
    case Type.BOOLEAN:
    case Type.BYTE:
    case Type.CHAR:
    case Type.SHORT:
    case Type.INT:
        v.visitInsn(Opcodes.ICONST_0);/*from w ww.j  av a  2s .  c  o  m*/
        v.directVarInsn(Opcodes.ISTORE, index);
        break;
    case Type.LONG:
        v.visitInsn(Opcodes.LCONST_0);
        v.directVarInsn(Opcodes.LSTORE, index);
        break;
    case Type.FLOAT:
        v.visitInsn(Opcodes.FCONST_0);
        v.directVarInsn(Opcodes.FSTORE, index);
        break;
    case Type.DOUBLE:
        v.visitInsn(Opcodes.DCONST_0);
        v.directVarInsn(Opcodes.DSTORE, index);
        break;
    case Type.OBJECT:
        v.visitInsn(Opcodes.ACONST_NULL);
        v.directVarInsn(Opcodes.ASTORE, index);
        break;
    default:
        throw new UnsupportedOperationException();
    }
}

From source file:org.brutusin.instrumentation.utils.TreeInstructions.java

License:Apache License

public static VarInsnNode getStoreInst(Type type, int position) {
    int opCode = -1;
    switch (type.getDescriptor().charAt(0)) {
    case 'B':
        opCode = Opcodes.ISTORE;/* w  w w  . j a va  2s. c  om*/
        break;
    case 'C':
        opCode = Opcodes.ISTORE;
        break;
    case 'D':
        opCode = Opcodes.DSTORE;
        break;
    case 'F':
        opCode = Opcodes.FSTORE;
        break;
    case 'I':
        opCode = Opcodes.ISTORE;
        break;
    case 'J':
        opCode = Opcodes.LSTORE;
        break;
    case 'L':
        opCode = Opcodes.ASTORE;
        break;
    case '[':
        opCode = Opcodes.ASTORE;
        break;
    case 'Z':
        opCode = Opcodes.ISTORE;
        break;
    case 'S':
        opCode = Opcodes.ISTORE;
        break;
    default:
        throw new ClassFormatError("Invalid method signature: " + type.getDescriptor());
    }
    return new VarInsnNode(opCode, position);
}

From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java

License:Open Source License

@Override
public void visitVarInsn(final int opcode, final int var) {
    T t = null;//from w  ww.  ja v  a2  s . com

    switch (opcode) {
    /********
     * LOAD *
     ********/
    case Opcodes.ALOAD:
        t = T.REF;
        // fall through
    case Opcodes.DLOAD:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FLOAD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ILOAD:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LLOAD:
        if (t == null) {
            t = T.LONG;
        }
        add(new LOAD(this.ops.size(), opcode, this.line, t, var));
        break;
    /*********
     * STORE *
     *********/
    case Opcodes.ASTORE:
        t = T.AREF; // RET allowed too
        // fall through
    case Opcodes.DSTORE:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FSTORE:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ISTORE:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LSTORE:
        if (t == null) {
            t = T.LONG;
        }
        add(new STORE(this.ops.size(), opcode, this.line, t, var));
        break;
    /*******
     * RET *
     *******/
    case Opcodes.RET: {
        add(new RET(this.ops.size(), opcode, this.line, var));
        break;
    }
    default:
        log.warn(getM() + ": Unknown var insn opcode '" + opcode + "'!");
    }
}

From source file:org.elasticsearch.painless.node.SSource.java

License:Apache License

@Override
void write(MethodWriter writer, Globals globals) {
    if (reserved.usesScore()) {
        // if the _score value is used, we do this once:
        // final double _score = scorer.score();
        Variable scorer = mainMethod.getVariable(null, Locals.SCORER);
        Variable score = mainMethod.getVariable(null, Locals.SCORE);

        writer.visitVarInsn(Opcodes.ALOAD, scorer.getSlot());
        writer.invokeVirtual(WriterConstants.SCORER_TYPE, WriterConstants.SCORER_SCORE);
        writer.visitInsn(Opcodes.F2D);//from ww  w . j a  va 2s .  com
        writer.visitVarInsn(Opcodes.DSTORE, score.getSlot());
    }

    if (reserved.usesCtx()) {
        // if the _ctx value is used, we do this once:
        // final Map<String,Object> ctx = input.get("ctx");

        Variable input = mainMethod.getVariable(null, Locals.PARAMS);
        Variable ctx = mainMethod.getVariable(null, Locals.CTX);

        writer.visitVarInsn(Opcodes.ALOAD, input.getSlot());
        writer.push(Locals.CTX);
        writer.invokeInterface(MAP_TYPE, MAP_GET);
        writer.visitVarInsn(Opcodes.ASTORE, ctx.getSlot());
    }

    if (reserved.getMaxLoopCounter() > 0) {
        // if there is infinite loop protection, we do this once:
        // int #loop = settings.getMaxLoopCounter()

        Variable loop = mainMethod.getVariable(null, Locals.LOOP);

        writer.push(reserved.getMaxLoopCounter());
        writer.visitVarInsn(Opcodes.ISTORE, loop.getSlot());
    }

    for (AStatement statement : statements) {
        statement.write(writer, globals);
    }

    if (!methodEscape) {
        writer.visitInsn(Opcodes.ACONST_NULL);
        writer.returnValue();
    }
}

From source file:org.evosuite.graphs.cfg.ASMWrapper.java

License:Open Source License

/**
 * <p>//ww w .j  a v a2 s .  c om
 * isLocalVarDefinition
 * </p>
 * 
 * @return a boolean.
 */
public boolean isLocalVariableDefinition() {
    return asmNode.getOpcode() == Opcodes.ISTORE || asmNode.getOpcode() == Opcodes.LSTORE
            || asmNode.getOpcode() == Opcodes.FSTORE || asmNode.getOpcode() == Opcodes.DSTORE
            || asmNode.getOpcode() == Opcodes.ASTORE || asmNode.getOpcode() == Opcodes.IINC
            || isLocalArrayDefinition();
}