Example usage for org.objectweb.asm Opcodes GETFIELD

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

Introduction

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

Prototype

int GETFIELD

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

Click Source Link

Usage

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildDomainMethod(ClassVisitor cv, String className) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "getDomain", "()I", null, null);
    mv.visitCode();//from   w w w  .  jav a2s  .c om

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "domain", "I");
    mv.visitInsn(Opcodes.IRETURN);

    mv.visitMaxs(2, 1);
    mv.visitEnd();
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildIndexMethod(ClassVisitor cv, String className) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "index", "()I", null, null);
    mv.visitCode();//  w ww . ja va  2 s.  co m

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "index", "I");
    mv.visitInsn(Opcodes.IRETURN);

    mv.visitMaxs(2, 1);
    mv.visitEnd();
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildForkMethod(ClassVisitor cv, String className) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "fork", "()" + Type.getDescriptor(Matcher.class),
            null, null);/*from   w  w w  .ja  v a2s. c o m*/
    mv.visitCode();

    mv.visitTypeInsn(Opcodes.NEW, className);
    mv.visitInsn(Opcodes.DUP);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", "()V", false);

    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "domain", "I");
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I");

    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I");
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I");

    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "index", "I");
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "index", "I");

    mv.visitInsn(Opcodes.ARETURN);

    mv.visitMaxs(2, 1);
    mv.visitEnd();
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildEndMethod(ClassVisitor cv, String className, Dfa dfa) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "end", "()" + Type.getDescriptor(Matcher.class), null,
            null);//www. j av  a2s .co m

    stateLabels = new Label[dfa.getStates().size()];
    Arrays.setAll(stateLabels, i -> new Label());
    int[] keys = new int[dfa.getStates().size()];
    Arrays.setAll(keys, IntUnaryOperator.identity());

    saveLabel = new Label();
    errorLabel = new Label();

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I");
    mv.visitLookupSwitchInsn(errorLabel, keys, stateLabels);

    for (int i = 0; i < dfa.getStates().size(); ++i) {
        mv.visitLabel(stateLabels[i]);
        DfaTransition transition = dfa.getStates().get(i).getTransition(-1);
        if (transition == null) {
            mv.visitJumpInsn(Opcodes.GOTO, errorLabel);
        } else {
            DfaState target = transition.getTarget();
            mv.visitIntInsn(Opcodes.SIPUSH, transition.getTarget().getIndex());
            mv.visitVarInsn(Opcodes.ISTORE, 1);
            mv.visitIntInsn(Opcodes.SIPUSH, !target.isTerminal() ? -1 : target.getDomains()[0]);
            mv.visitVarInsn(Opcodes.ISTORE, 2);
            debug(mv, "DFA: " + i + " .-> " + target.getIndex() + " " + Arrays.toString(target.getDomains()));
            mv.visitJumpInsn(Opcodes.GOTO, saveLabel);
        }
    }

    mv.visitLabel(errorLabel);
    debug(mv, "DFA: error");
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, 1);
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, 2);
    mv.visitLabel(saveLabel);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ARETURN);

    mv.visitMaxs(3, 3);
    mv.visitEnd();
}

From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java

License:Apache License

private void buildWorkerMethod(ClassVisitor cv, String className, Dfa dfa) {
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "feed",
            "(Ljava/lang/String;IIZ)" + Type.getDescriptor(Matcher.class), null, null);
    mv.visitCode();/*w w w . jav a  2s.c  o m*/

    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I");
    mv.visitVarInsn(Opcodes.ISTORE, 5);

    errorLabel = new Label();
    saveLabel = new Label();
    loopLabel = new Label();
    continueLabel = new Label();

    mv.visitLabel(loopLabel);
    generateLengthGuard(mv);

    stateLabels = new Label[dfa.getStates().size()];
    Arrays.setAll(stateLabels, i -> new Label());
    int[] keys = new int[dfa.getStates().size()];
    Arrays.setAll(keys, IntUnaryOperator.identity());

    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitLookupSwitchInsn(errorLabel, keys, stateLabels);

    mv.visitLabel(continueLabel);
    mv.visitIincInsn(2, 1);
    mv.visitJumpInsn(Opcodes.GOTO, loopLabel);

    mv.visitLabel(errorLabel);
    debug(mv, "DFA: error");
    mv.visitInsn(Opcodes.ICONST_M1);
    mv.visitVarInsn(Opcodes.ISTORE, 5);

    mv.visitLabel(saveLabel);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 5);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ILOAD, 2);
    mv.visitFieldInsn(Opcodes.PUTFIELD, className, "index", "I");
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitInsn(Opcodes.ARETURN);

    for (int i = 0; i < dfa.getStates().size(); ++i) {
        mv.visitLabel(stateLabels[i]);
        DfaState state = dfa.getStates().get(i);
        generateTransitions(state, mv);
    }

    mv.visitMaxs(3, 6);
    mv.visitEnd();
}

From source file:org.testeoa.estatica.AdapterDUG.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // insere a descrio da instruo
    String instrucao = getInstrucao(opcode);
    instrucao += " " + owner + "." + name + " " + desc;
    addInstrucao(instrucao);/*from  ww  w . ja v a 2 s.  c o  m*/
    // Anlise do Fluxo de Dados
    String[] s = owner.split("/");
    String o = s[s.length - 1];
    if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) {
        verticeAtual.inserirDefinicao(o + "." + name);
    }
    if (opcode == Opcodes.GETFIELD || opcode == Opcodes.GETSTATIC) {
        verticeAtual.inserirUso(o + "." + name);
    }
    super.visitFieldInsn(opcode, owner, name, desc);
}

From source file:pl.asie.foamfix.coremod.patches.ReturnIfBooleanTruePatch.java

License:Open Source License

public ReturnIfBooleanTruePatch(String optionName, String... methods) {
    this.optionName = optionName;
    this.methods = ImmutableSet.copyOf(methods);

    list = new InsnList();
    Label l = new Label();
    LabelNode ln = new LabelNode(l);
    list.add(new FieldInsnNode(Opcodes.GETSTATIC, "pl/asie/foamfix/shared/FoamFixShared", "config",
            "Lpl/asie/foamfix/shared/FoamFixConfig;"));
    list.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/foamfix/shared/FoamFixConfig", optionName, "Z"));
    list.add(new JumpInsnNode(Opcodes.IFEQ, ln));
    list.add(new InsnNode(Opcodes.RETURN));
    list.add(ln);// w  w w  .  ja v a 2  s . c  o m
    list.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
}

From source file:portablejim.veinminer.asm.ItemInWorldManagerTransformer.java

License:Open Source License

private InsnList buildBlockIdFunctionCall(String obfuscatedClassName, String worldType, int blockVarIndex) {
    InsnList blockIdFunctionCall = new InsnList();
    blockIdFunctionCall.add(new TypeInsnNode(Opcodes.NEW, blockIdClassName));
    blockIdFunctionCall.add(new InsnNode(Opcodes.DUP));
    blockIdFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, 0));
    blockIdFunctionCall.add(new FieldInsnNode(Opcodes.GETFIELD, obfuscatedClassName.replace(".", "/"),
            getCorrectName("theWorld"), typemap.get(getCorrectName("theWorld"))));
    blockIdFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 1));
    blockIdFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 2));
    blockIdFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 3));
    blockIdFunctionCall.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, blockIdClassName, "<init>",
            String.format("(%sIII)V", worldType)));

    blockIdFunctionCall.add(new VarInsnNode(Opcodes.ASTORE, blockVarIndex));

    return blockIdFunctionCall;
}

From source file:portablejim.veinminer.asm.ItemInWorldManagerTransformer.java

License:Open Source License

private int insertCallAfterTryHarvestBlockFunction(MethodNode curMethod, String obfuscatedClassName,
        int startIndex) throws IndexOutOfBoundsException {
    LocalVariablesSorter varSorter = new LocalVariablesSorter(curMethod.access, curMethod.desc, curMethod);

    String worldType = typemap.get(getCorrectName("theWorld"));
    String playerType = typemap.get(getCorrectName("thisPlayerMP"));

    while (!isMethodWithName(curMethod.instructions.get(startIndex), "tryHarvestBlock")) {
        ++startIndex;//from  ww  w .j a  va  2s. c om
    }

    do {
        --startIndex;
    } while (curMethod.instructions.get(startIndex).getType() == AbstractInsnNode.VAR_INSN);

    int blockVarIndex = varSorter.newLocal(Type.getType(BlockID.class));
    curMethod.instructions.insert(curMethod.instructions.get(startIndex),
            buildBlockIdFunctionCall(obfuscatedClassName, worldType, blockVarIndex));
    ++startIndex;

    while (!isMethodWithName(curMethod.instructions.get(startIndex), "tryHarvestBlock")) {
        ++startIndex;
    }

    // Add variable to store result
    int newVarIndex = varSorter.newLocal(Type.BOOLEAN_TYPE);
    VarInsnNode newVar = new VarInsnNode(Opcodes.ISTORE, newVarIndex);
    curMethod.instructions.insert(curMethod.instructions.get(startIndex), newVar);
    ++startIndex;

    // Add in function call to call function
    InsnList veinMinerFunctionCall = new InsnList();
    veinMinerFunctionCall
            .add(new FieldInsnNode(Opcodes.GETSTATIC, targetClassName, "instance", targetClassType));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, 0));
    veinMinerFunctionCall.add(new FieldInsnNode(Opcodes.GETFIELD, obfuscatedClassName.replace(".", "/"),
            getCorrectName("theWorld"), typemap.get(getCorrectName("theWorld"))));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, 0));
    veinMinerFunctionCall.add(new FieldInsnNode(Opcodes.GETFIELD, obfuscatedClassName.replace(".", "/"),
            getCorrectName("thisPlayerMP"), typemap.get(getCorrectName("thisPlayerMP"))));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 1));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 2));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 3));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, newVarIndex));
    veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, blockVarIndex));

    String blockIdClassType = String.format("L%s;", blockIdClassName);
    veinMinerFunctionCall.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, targetClassName, targetMethodName,
            String.format(targetMethodType, worldType, playerType, blockIdClassType)));
    curMethod.instructions.insert(curMethod.instructions.get(startIndex), veinMinerFunctionCall);
    ++startIndex;

    // Get rid of un-needed POP.
    while (curMethod.instructions.get(startIndex).getOpcode() != Opcodes.POP) {
        ++startIndex;
    }
    curMethod.instructions.remove(curMethod.instructions.get(startIndex));

    return startIndex;
}

From source file:pxb.android.dex2jar.asm.PDescMethodVisitor.java

License:Apache License

public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    super.visitFieldInsn(opcode, owner, name, desc);
    switch (opcode) {
    case Opcodes.GETFIELD:
        e((Type) stack.pop(), Type.getType(owner));
        stack.push(Type.getType(desc));
        break;/* www. j  a  v  a2s .c o  m*/
    case Opcodes.PUTFIELD:
        e((Type) stack.pop(), Type.getType(desc));
        e((Type) stack.pop(), Type.getType(owner));
        break;
    case Opcodes.GETSTATIC:
        stack.push(Type.getType(desc));
        break;
    case Opcodes.PUTSTATIC:
        e((Type) stack.pop(), Type.getType(desc));
        break;
    }
}