Search in sources :

Example 86 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class JumpInsnNodeSerializer method deserialize.

@Override
public JumpInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = (JsonObject) json;
    int opcode = jsonObject.get("opcode").getAsInt();
    LabelNode labelNode = context.deserialize(jsonObject.get("local"), List.class);
    return new JumpInsnNode(opcode, labelNode);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JsonObject(com.google.gson.JsonObject) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Example 87 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.

the class ControlFlowGraphDumper method verifyRanges.

private void verifyRanges() {
    for (TryCatchBlockNode tc : m.tryCatchBlocks) {
        int start = -1, end = -1, handler = -1;
        for (int i = 0; i < m.instructions.size(); i++) {
            AbstractInsnNode ain = m.instructions.get(i);
            if (!(ain instanceof LabelNode))
                continue;
            Label l = ((LabelNode) ain).getLabel();
            if (l == tc.start.getLabel())
                start = i;
            if (l == tc.end.getLabel()) {
                if (start == -1)
                    throw new IllegalStateException("Try block end before start " + m);
                end = i;
            }
            if (l == tc.handler.getLabel()) {
                handler = i;
            }
        }
        if (start == -1 || end == -1 || handler == -1)
            throw new IllegalStateException("Try/catch endpoints missing: " + start + " " + end + " " + handler + m);
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) Label(org.objectweb.asm.Label) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 88 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project bytecode-viewer by Konloch.

the class InstructionPrinter method printLookupSwitchInsnNode.

protected String printLookupSwitchInsnNode(LookupSwitchInsnNode lin) {
    StringBuilder line = new StringBuilder(nameOpcode(lin.getOpcode()) + ": \n");
    List<?> keys = lin.keys;
    List<?> labels = lin.labels;
    for (int i = 0; i < keys.size(); i++) {
        int key = (Integer) keys.get(i);
        LabelNode label = (LabelNode) labels.get(i);
        line.append("                val: ").append(key).append(" -> ").append("L").append(resolveLabel(label)).append("\n");
    }
    line.append("                default" + " -> L").append(resolveLabel(lin.dflt));
    return line.toString();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode)

Example 89 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project atlas by alibaba.

the class TBIncrementalSupportVisitor method visitMethod.

/**
 * Insert Constructor specific logic({@link ConstructorRedirection} and
 * {@link ConstructorBuilder}) for constructor redirecting or
 * normal method redirecting ({@link MethodRedirection}) for other methods.
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    access = transformAccessForInstantRun(access);
    MethodVisitor defaultVisitor = super.visitMethod(access, name, desc, signature, exceptions);
    MethodNode method = checkNotNull(getMethodByNameInClass(name, desc, classNode), "Method found by visitor but not in the pre-parsed class node.");
    if (!supportAddCallSuper) {
        method.instructions.accept(new MethodVisitor(api) {

            @Override
            public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
                if (opcode == Opcodes.INVOKESPECIAL && !owner.equals(visitedClassName)) {
                    visitSuperMethods.add(name + "." + desc);
                }
                super.visitMethodInsn(opcode, owner, name, desc, itf);
            }
        });
    }
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        return defaultVisitor;
    }
    boolean hasIncompatibleChange = InstantRunMethodVerifier.verifyMethod(method) != InstantRunVerifierStatus.COMPATIBLE;
    if (hasIncompatibleChange || disableRedirectionForClass || !isAccessCompatibleWithInstantRun(access) || name.equals(ByteCodeUtils.CLASS_INITIALIZER)) {
        return defaultVisitor;
    } else {
        ArrayList<Type> args = new ArrayList<>(Arrays.asList(Type.getArgumentTypes(desc)));
        boolean isStatic = (access & Opcodes.ACC_STATIC) != 0;
        if (!isStatic) {
            args.add(0, Type.getType(Object.class));
        }
        // Install the Jsr/Ret inliner adapter, we have had reports of code still using the
        // Jsr/Ret deprecated byte codes.
        // see https://code.google.com/p/android/issues/detail?id=220019
        JSRInlinerAdapter jsrInlinerAdapter = new JSRInlinerAdapter(defaultVisitor, access, name, desc, signature, exceptions);
        ISMethodVisitor mv = new ISMethodVisitor(jsrInlinerAdapter, access, name, desc);
        if (name.equals(ByteCodeUtils.CONSTRUCTOR)) {
            if (patchInitMethod) {
                Constructor constructor = ConstructorBuilder.build(visitedClassName, method);
                LabelNode start = new LabelNode();
                method.instructions.insert(constructor.loadThis, start);
                if (constructor.lineForLoad != -1) {
                    // Record the line number from the start of LOAD_0 for uninitialized 'this'.
                    // This allows a breakpoint to be set at the line with this(...) or super(...)
                    // call in the constructor.
                    method.instructions.insert(constructor.loadThis, new LineNumberNode(constructor.lineForLoad, start));
                }
                mv.addRedirection(new TBConstructorRedirection(start, constructor, args));
            } else {
                return defaultVisitor;
            }
        } else {
            mv.addRedirection(new TBMethodRedirection(new LabelNode(mv.getStartLabel()), name + "." + desc, args, Type.getReturnType(desc)));
        }
        method.accept(mv);
        return null;
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) JSRInlinerAdapter(org.objectweb.asm.commons.JSRInlinerAdapter) MethodNode(org.objectweb.asm.tree.MethodNode)

Aggregations

LabelNode (org.objectweb.asm.tree.LabelNode)89 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)37 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)32 Label (org.objectweb.asm.Label)28 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)23 InsnList (org.objectweb.asm.tree.InsnList)22 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)21 InsnNode (org.objectweb.asm.tree.InsnNode)20 MethodNode (org.objectweb.asm.tree.MethodNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)17 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)16 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)10 Type (org.objectweb.asm.Type)8 LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)8 LinkedList (java.util.LinkedList)6 ArrayList (java.util.ArrayList)5 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)5