Example usage for org.objectweb.asm Opcodes ISTORE

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

Introduction

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

Prototype

int ISTORE

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

Click Source Link

Usage

From source file:asmlib.Type.java

License:Open Source License

/** Mtodo que retorna o opcode certo para o tipo de varivel que se quer fazer store.
  * Opcodes disponveis:/*w  w w.  ja v  a  2s.c  o m*/
  * - ISTORE para boolean, byte, char, short, int
  * - LSTORE para long
  * - FSTORE para float
  * - DSTORE para double
  * - ASTORE para referncia (objecto ou array)
  **/
public int getStoreInsn() {
    char c = bytecodeName().charAt(0);
    switch (c) {
    case 'Z': // boolean
    case 'B': // byte
    case 'C': // char
    case 'S': // short
    case 'I': // int
        return Opcodes.ISTORE;
    case 'J': // long
        return Opcodes.LSTORE;
    case 'F': // float
        return Opcodes.FSTORE;
    case 'D': // double
        return Opcodes.DSTORE;
    case '[': // Algum tipo de array
    case 'L': // objecto
    case 'T': // objecto (generics)
        return Opcodes.ASTORE;
    }
    throw new InstrumentationException("Unknown fieldType in getStoreInsn");
}

From source file:blue.origami.asm.OGeneratorAdapter.java

License:Apache License

/**
 * create new local variable entry and store stack top value to created
 * entry/*from   w ww  . ja va2s .c  o  m*/
 *
 * @param varName
 * @param t
 * @return
 */

public VarEntry createNewVarAndStore(String varName, OType t) {
    VarEntry entry = this.varScopes.peek().newVarEntry(varName, t);
    this.countLocalSlots(t);
    Type typeDesc = Type.getType(t.typeDesc(0));
    this.visitVarInsn(typeDesc.getOpcode(Opcodes.ISTORE), entry.getVarIndex());
    return entry;
}

From source file:blue.origami.asm.OGeneratorAdapter.java

License:Apache License

/**
 * store stack top value to local variable.
 *
 * @param entry/*  w  w  w .jav  a 2  s.  c  o m*/
 */
public void storeToVar(VarEntry entry) {
    Type typeDesc = Type.getType(entry.getVarClass().typeDesc(0));
    this.visitVarInsn(typeDesc.getOpcode(Opcodes.ISTORE), entry.getVarIndex());
}

From source file:br.usp.each.saeg.badua.core.internal.instr.IntegerInitProbe.java

License:Open Source License

@Override
public void accept(final MethodVisitor mv) {
    mv.visitInsn(Opcodes.ICONST_0);//from   w  w  w.j a v  a2 s  .co  m
    mv.visitVarInsn(Opcodes.ISTORE, vCovered);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitVarInsn(Opcodes.ISTORE, vAlive);
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, vSleepy);
}

From source file:br.usp.each.saeg.badua.core.internal.instr.IntegerProbe.java

License:Open Source License

@Override
public void accept(final MethodVisitor mv) {

    // update covered
    if (potcov != 0) {
        mv.visitVarInsn(Opcodes.ILOAD, vAlive);

        if (!singlePredecessor && potcovpuse != 0) {
            mv.visitVarInsn(Opcodes.ILOAD, vSleepy);
            mv.visitInsn(Opcodes.IAND);/*from   w ww  .j a va  2 s .c o m*/
        }

        InstrSupport.push(mv, (int) potcov);
        mv.visitInsn(Opcodes.IAND);
        mv.visitVarInsn(Opcodes.ILOAD, vCovered);
        mv.visitInsn(Opcodes.IOR);
        mv.visitVarInsn(Opcodes.ISTORE, vCovered);
    }

    // update alive
    if (disabled != 0) {
        InstrSupport.push(mv, ~(int) disabled);
        mv.visitVarInsn(Opcodes.ILOAD, vAlive);
        mv.visitInsn(Opcodes.IAND);
    }
    if (born != 0) {
        if (disabled == 0) {
            mv.visitVarInsn(Opcodes.ILOAD, vAlive);
        }
        InstrSupport.push(mv, (int) born);
        mv.visitInsn(Opcodes.IOR);
    }
    if (disabled != 0 || born != 0) {
        mv.visitVarInsn(Opcodes.ISTORE, vAlive);
    }

    // update sleepy
    InstrSupport.push(mv, ~(int) sleepy);
    mv.visitVarInsn(Opcodes.ISTORE, vSleepy);

}

From source file:br.usp.each.saeg.badua.core.internal.instr.IntegerRootProbe.java

License:Open Source License

@Override
public void accept(final MethodVisitor mv) {
    if (born != 0) {
        InstrSupport.push(mv, (int) born);
        mv.visitVarInsn(Opcodes.ISTORE, vAlive);
    }// www .  j a va 2 s. co m
    if (sleepy != 0) {
        InstrSupport.push(mv, ~(int) sleepy);
        mv.visitVarInsn(Opcodes.ISTORE, vSleepy);
    }
}

From source file:br.usp.each.saeg.badua.test.validation.MaxTest.java

License:Open Source License

@Override
@Before//from   w w w. j  a  v  a  2 s . co m
public void setUp() throws Exception {
    super.setUp();

    final int classVersion = Opcodes.V1_6;
    final int classAccessor = Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER;
    final String className = "Max";
    final String superName = "java/lang/Object";

    final int methodAccessor = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
    final String methodName = "max";
    final String methodDesc = "([II)I";

    final ClassWriter cw = new ClassWriter(0);
    final MethodVisitor mw;

    cw.visit(classVersion, classAccessor, className, null, superName, null);
    mw = cw.visitMethod(methodAccessor, methodName, methodDesc, null, null);
    mw.visitCode();
    // block 0 (definitions {0, 1, 2, 3})
    mw.visitInsn(Opcodes.ICONST_0);
    mw.visitVarInsn(Opcodes.ISTORE, 2);
    mw.visitVarInsn(Opcodes.ALOAD, 0);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitIincInsn(2, 1);
    mw.visitInsn(Opcodes.IALOAD);
    mw.visitVarInsn(Opcodes.ISTORE, 3);
    // block 1 (p-uses {1, 2})
    final Label backLoop = new Label();
    mw.visitLabel(backLoop);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitVarInsn(Opcodes.ILOAD, 1);
    final Label breakLoop = new Label();
    mw.visitJumpInsn(Opcodes.IF_ICMPGE, breakLoop);
    // block 3 (p-uses {0, 2, 3})
    mw.visitVarInsn(Opcodes.ALOAD, 0);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitInsn(Opcodes.IALOAD);
    mw.visitVarInsn(Opcodes.ILOAD, 3);
    final Label jump = new Label();
    mw.visitJumpInsn(Opcodes.IF_ICMPLE, jump);
    // block 5 (definitions {3}, uses {0, 2})
    mw.visitVarInsn(Opcodes.ALOAD, 0);
    mw.visitVarInsn(Opcodes.ILOAD, 2);
    mw.visitInsn(Opcodes.IALOAD);
    mw.visitVarInsn(Opcodes.ISTORE, 3);
    // block 4 (definitions {2}, uses {2})
    mw.visitLabel(jump);
    mw.visitIincInsn(2, 1);
    mw.visitJumpInsn(Opcodes.GOTO, backLoop);
    // block 2 ( uses {3})
    mw.visitLabel(breakLoop);
    mw.visitVarInsn(Opcodes.ILOAD, 3);
    mw.visitInsn(Opcodes.IRETURN);
    mw.visitMaxs(2, 4);
    mw.visitEnd();
    cw.visitEnd();

    final byte[] bytes = cw.toByteArray();
    klass = addClass(className, bytes);
    method = klass.getMethod(methodName, int[].class, int.class);
    classId = CRC64.checksum(bytes);

    RT.init(new RuntimeData());
}

From source file:bytecode.InstructionExporter.java

License:Apache License

/**
 * Outputs a write operation, choosing both the correct opcode family
 * (variable write, array store, field put, etc.) and type.
 *
 * @param instruction Write instruction.
 * @return            <code>null</code>
 *///from w ww  .ja  va  2 s .  c om
@Override
public Void visit(Write instruction) {
    // Variable Stores
    if (instruction.getState() instanceof Variable) {
        Variable v = (Variable) instruction.getState();

        switch (v.getType().getSort()) {
        case LONG:
            mv.visitVarInsn(Opcodes.LSTORE, v.getIndex());
            break;
        case FLOAT:
            mv.visitVarInsn(Opcodes.FSTORE, v.getIndex());
            break;
        case DOUBLE:
            mv.visitVarInsn(Opcodes.DSTORE, v.getIndex());
            break;
        case REF:
            mv.visitVarInsn(Opcodes.ASTORE, v.getIndex());
            break;
        default:
            mv.visitVarInsn(Opcodes.ISTORE, v.getIndex());
            break;
        }
        // Array Stores
    } else if (instruction.getState() instanceof ArrayElement) {
        switch (instruction.getState().getType().getSort()) {
        case INT:
            mv.visitInsn(Opcodes.IASTORE);
            break;
        case LONG:
            mv.visitInsn(Opcodes.LASTORE);
            break;
        case FLOAT:
            mv.visitInsn(Opcodes.FASTORE);
            break;
        case DOUBLE:
            mv.visitInsn(Opcodes.DASTORE);
            break;
        case REF:
            mv.visitInsn(Opcodes.AASTORE);
            break;
        case BYTE:
            mv.visitInsn(Opcodes.BASTORE);
            break;
        case BOOL:
            mv.visitInsn(Opcodes.BASTORE);
            break;
        case CHAR:
            mv.visitInsn(Opcodes.CASTORE);
            break;
        case SHORT:
            mv.visitInsn(Opcodes.SASTORE);
            break;
        }
        // Static Writes
    } else if (instruction.getState() instanceof Field) {
        Field f = (Field) instruction.getState();

        mv.visitFieldInsn(Opcodes.PUTSTATIC, f.getOwner().getName(), f.getName(), f.getType().getDescriptor());
        // Field Writes
    } else if (instruction.getState() instanceof InstanceField) {
        Field f = (Field) ((InstanceField) instruction.getState()).getField();

        mv.visitFieldInsn(Opcodes.PUTFIELD, f.getOwner().getName(), f.getName(), f.getType().getDescriptor());
    }

    return null;
}

From source file:bytecode.MethodImporter.java

License:Apache License

/**
 * Imports variable load and store operations, as well as RET?!?
 *
 * @param opcode Opcode.//from ww w .  j a v a  2 s . c om
 * @param var    Variable index.
 */
@Override
public void visitVarInsn(final int opcode, final int var) {
    switch (opcode) {
    case Opcodes.ILOAD:
        createVarRead(var, Type.INT);
        break;
    case Opcodes.LLOAD:
        createVarRead(var, Type.LONG);
        break;
    case Opcodes.FLOAD:
        createVarRead(var, Type.FLOAT);
        break;
    case Opcodes.DLOAD:
        createVarRead(var, Type.DOUBLE);
        break;
    case Opcodes.ALOAD:
        createVarRead(var, Type.getFreshRef());
        break;
    case Opcodes.ISTORE:
        createVarWrite(var, Type.INT);
        break;
    case Opcodes.LSTORE:
        createVarWrite(var, Type.LONG);
        break;
    case Opcodes.FSTORE:
        createVarWrite(var, Type.FLOAT);
        break;
    case Opcodes.DSTORE:
        createVarWrite(var, Type.DOUBLE);
        break;
    case Opcodes.ASTORE:
        createVarWrite(var, Type.getFreshRef());
        break;

    // TODO: RET (paired with JSR)
    case Opcodes.RET:
        throw new RuntimeException("visitVarInsn: RET");
    }
}

From source file:Client.JClassPatcher.java

License:Open Source License

private void patchRenderer(ClassNode node) {
    Logger.Info("Patching renderer (" + node.name + ".class)");

    Iterator<MethodNode> methodNodeList = node.methods.iterator();
    while (methodNodeList.hasNext()) {
        MethodNode methodNode = methodNodeList.next();

        // Renderer present hook
        if (methodNode.desc.equals("(Ljava/awt/Graphics;III)V")) {
            AbstractInsnNode findNode = methodNode.instructions.getFirst();
            FieldInsnNode imageNode = null;

            while (findNode.getOpcode() != Opcodes.POP) {
                findNode = findNode.getNext();
                if (findNode == null) {
                    Logger.Error("Unable to find present hook");
                    break;
                }//w w  w. j av a2  s.c o  m
            }

            while (findNode.getOpcode() != Opcodes.INVOKESPECIAL) {
                if (findNode.getOpcode() == Opcodes.GETFIELD)
                    imageNode = (FieldInsnNode) findNode;

                AbstractInsnNode prev = findNode.getPrevious();
                methodNode.instructions.remove(findNode);
                findNode = prev;
            }

            methodNode.instructions.insert(findNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Renderer",
                    "present", "(Ljava/awt/Graphics;Ljava/awt/Image;)V", false));
            methodNode.instructions.insert(findNode,
                    new FieldInsnNode(Opcodes.GETFIELD, node.name, imageNode.name, imageNode.desc));
            methodNode.instructions.insert(findNode, new VarInsnNode(Opcodes.ALOAD, 0));
            methodNode.instructions.insert(findNode, new VarInsnNode(Opcodes.ALOAD, 1));
        } else if (methodNode.name.equals("a") && methodNode.desc.equals("(IILjava/lang/String;IIBI)V")) {
            AbstractInsnNode start = methodNode.instructions.getFirst();
            while (start != null) {
                if (start.getOpcode() == Opcodes.ALOAD && start.getNext().getOpcode() == Opcodes.ILOAD
                        && start.getNext().getNext().getOpcode() == Opcodes.INVOKEVIRTUAL
                        && start.getNext().getNext().getNext().getOpcode() == Opcodes.ISTORE) {
                    break;
                }

                start = start.getNext();
            }
            start = start.getPrevious();

            LabelNode finishLabel = ((JumpInsnNode) start.getPrevious().getPrevious()).label;
            LabelNode failLabel = new LabelNode();

            methodNode.instructions.insertBefore(start, new IntInsnNode(Opcodes.BIPUSH, 126));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ALOAD, 3));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ILOAD, 10));
            methodNode.instructions.insertBefore(start,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C"));
            methodNode.instructions.insertBefore(start, new JumpInsnNode(Opcodes.IF_ICMPNE, failLabel));

            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ILOAD, 10));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.ICONST_5));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.IADD));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ALOAD, 3));
            methodNode.instructions.insertBefore(start,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I"));
            methodNode.instructions.insertBefore(start, new JumpInsnNode(Opcodes.IF_ICMPGE, failLabel));

            methodNode.instructions.insertBefore(start, new IntInsnNode(Opcodes.BIPUSH, 126));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ALOAD, 3));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ILOAD, 10));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.ICONST_5));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.IADD));
            methodNode.instructions.insertBefore(start,
                    new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C"));
            methodNode.instructions.insertBefore(start, new JumpInsnNode(Opcodes.IF_ICMPNE, failLabel));

            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ALOAD, 3));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ILOAD, 10));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.ICONST_1));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.IADD));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ILOAD, 10));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.ICONST_5));
            methodNode.instructions.insertBefore(start, new InsnNode(Opcodes.IADD));
            methodNode.instructions.insertBefore(start, new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
                    "java/lang/String", "substring", "(II)Ljava/lang/String;"));
            methodNode.instructions.insertBefore(start, new MethodInsnNode(Opcodes.INVOKESTATIC,
                    "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I"));
            methodNode.instructions.insertBefore(start, new VarInsnNode(Opcodes.ISTORE, 4));
            methodNode.instructions.insertBefore(start, new IincInsnNode(10, 5));

            methodNode.instructions.insertBefore(start, new JumpInsnNode(Opcodes.GOTO, finishLabel));

            methodNode.instructions.insertBefore(start, failLabel);
        }
    }
}