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]);
}
}
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;
}
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());
}
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();
}
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;
}
Aggregations