Search in sources :

Example 11 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project quasar by puniverse.

the class InstrumentMethod method collectCallsites.

private void collectCallsites() {
    if (suspCallsBcis == null) {
        suspCallsBcis = new int[8];
        final int numIns = mn.instructions.size();
        int currSourceLine = -1;
        int count = 0;
        final Set<String> callSiteNames = new HashSet<>();
        for (int i = 0; i < numIns; i++) {
            final Frame f = frames[i];
            if (f != null) {
                // reachable ?
                final AbstractInsnNode in = mn.instructions.get(i);
                if (in.getType() == AbstractInsnNode.LINE) {
                    final LineNumberNode lnn = (LineNumberNode) in;
                    currSourceLine = lnn.line;
                    if (startSourceLine == -1 || currSourceLine < startSourceLine)
                        startSourceLine = currSourceLine;
                    if (endSourceLine == -1 || currSourceLine > endSourceLine)
                        endSourceLine = currSourceLine;
                } else if (in.getType() == AbstractInsnNode.METHOD_INSN || in.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) {
                    if (isSuspendableCall(db, in)) {
                        if (count >= suspCallsBcis.length)
                            suspCallsBcis = Arrays.copyOf(suspCallsBcis, suspCallsBcis.length * 2);
                        if (count >= suspCallsSourceLines.length)
                            suspCallsSourceLines = Arrays.copyOf(suspCallsSourceLines, suspCallsSourceLines.length * 2);
                        suspCallsBcis[count] = i;
                        suspCallsSourceLines[count] = currSourceLine;
                        callSiteNames.add(getSuspendableCallName(in));
                        count++;
                    } else
                        possiblyWarnAboutBlocking(in);
                }
            }
        }
        if (count < suspCallsSourceLines.length)
            suspCallsSourceLines = Arrays.copyOf(suspCallsSourceLines, count);
        if (count < suspCallsBcis.length)
            suspCallsBcis = Arrays.copyOf(suspCallsBcis, count);
        suspCallsNames = callSiteNames.toArray(new String[0]);
    }
}
Also used : Frame(org.objectweb.asm.tree.analysis.Frame) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) HashSet(java.util.HashSet)

Example 12 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project jphp by jphp-compiler.

the class StmtCompiler method writeLabel.

public LabelNode writeLabel(MethodNode mv, int lineNumber) {
    LabelNode node = new LabelNode(new Label());
    mv.instructions.add(node);
    if (lineNumber != -1)
        mv.instructions.add(new LineNumberNode(lineNumber, node));
    return node;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) Label(org.objectweb.asm.Label) LineNumberNode(org.objectweb.asm.tree.LineNumberNode)

Example 13 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project jphp by jphp-compiler.

the class ForCompiler method write.

@Override
public void write(ForStmtToken token) {
    expr.writeDefineVariables(token.getInitLocal());
    for (ExprStmtToken expr : token.getInitExpr()) {
        this.expr.writeExpression(expr, false, false);
    }
    expr.writeUndefineVariables(token.getInitLocal());
    expr.writeDefineVariables(token.getLocal());
    for (VariableExprToken variable : token.getIterationLocal()) {
        // TODO optimize this for Dynamic Values of variables
        LocalVariable local = method.getLocalVariable(variable.getName());
        local.setValue(null);
    }
    LabelNode start = expr.writeLabel(node, token.getMeta().getStartLine());
    LabelNode iter = new LabelNode();
    LabelNode end = new LabelNode();
    for (Iterator<ExprStmtToken> i = token.getConditionExpr().iterator(); i.hasNext(); ) {
        ExprStmtToken expr = i.next();
        if (i.hasNext()) {
            this.expr.writeExpression(expr, false, false);
        } else {
            this.expr.writeExpression(expr, true, false);
            this.expr.writePopBoolean();
            add(new JumpInsnNode(IFEQ, end));
            this.expr.stackPop();
        }
    }
    method.pushJump(end, iter);
    expr.write(BodyStmtToken.class, token.getBody());
    method.popJump();
    add(iter);
    for (ExprStmtToken expr : token.getIterationExpr()) {
        this.expr.writeExpression(expr, false, false);
    }
    add(new JumpInsnNode(GOTO, start));
    add(end);
    add(new LineNumberNode(token.getMeta().getEndLine(), end));
    expr.writeUndefineVariables(token.getLocal());
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) LineNumberNode(org.objectweb.asm.tree.LineNumberNode)

Example 14 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project Minechem by iopleke.

the class MinechemTransformer method replaceBytes.

private byte[] replaceBytes(Method method, CodeBlock codeBlock, byte[] data) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(data);
    classReader.accept(classNode, ClassReader.EXPAND_FRAMES);
    MethodNode methodNode = getMethodByName(classNode, method);
    AbstractInsnNode pos = null;
    boolean delete = false;
    boolean done = false;
    int start = codeBlock.getLinesAfterStart();
    int end = codeBlock.getLinesAfterEnd() + 1;
    for (Iterator<AbstractInsnNode> itr = methodNode.instructions.iterator(); itr.hasNext(); ) {
        AbstractInsnNode node = itr.next();
        if (node instanceof LineNumberNode) {
            LineNumberNode lineNode = (LineNumberNode) node;
            if (lineNode.line >= codeBlock.getStartLine()) {
                delete = true;
            }
            if (lineNode.line >= codeBlock.getEndLine()) {
                done = true;
            }
        }
        if (delete) {
            if (done) {
                if (end-- > 0) {
                    methodNode.instructions.remove(node);
                    continue;
                }
                pos = node;
                break;
            }
            if (--start < 0) {
                methodNode.instructions.remove(node);
            }
        }
    }
    methodNode.instructions.insertBefore(pos, codeBlock.getInsnList());
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodNode(org.objectweb.asm.tree.MethodNode) ClassReader(org.objectweb.asm.ClassReader) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) ClassWriter(org.objectweb.asm.ClassWriter)

Example 15 with LineNumberNode

use of org.objectweb.asm.tree.LineNumberNode in project Bookshelf by Darkhax-Minecraft.

the class InstructionComparator method getImportantList.

// TODO: Add documentation
public static InsnList getImportantList(InsnList list) {
    if (list.size() == 0) {
        return list;
    }
    final HashMap<LabelNode, LabelNode> labels = new HashMap<>();
    for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
        if (insn instanceof LabelNode) {
            labels.put((LabelNode) insn, (LabelNode) insn);
        }
    }
    final InsnList importantNodeList = new InsnList();
    for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
        if (insn instanceof LabelNode || insn instanceof LineNumberNode) {
            continue;
        }
        importantNodeList.add(insn.clone(labels));
    }
    return importantNodeList;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) HashMap(java.util.HashMap) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList)

Aggregations

LineNumberNode (org.objectweb.asm.tree.LineNumberNode)17 LabelNode (org.objectweb.asm.tree.LabelNode)10 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)8 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)6 FrameNode (org.objectweb.asm.tree.FrameNode)5 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)3 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)2 InsnList (org.objectweb.asm.tree.InsnList)2 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)2 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)2 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)1 CaseStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.CaseStmtToken)1 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)1 ControlDependenceGraph (org.evosuite.graphs.cdg.ControlDependenceGraph)1