use of org.objectweb.asm.tree.TryCatchBlockNode in project jacoco by jacoco.
the class SynchronizedFilter method filter.
public void filter(final String className, final String superClassName, final MethodNode methodNode, final IFilterOutput output) {
for (TryCatchBlockNode tryCatch : methodNode.tryCatchBlocks) {
if (tryCatch.type != null) {
continue;
}
if (tryCatch.start == tryCatch.handler) {
continue;
}
final AbstractInsnNode to = new Matcher(tryCatch.handler).match();
if (to == null) {
continue;
}
output.ignore(tryCatch.handler, to);
}
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project jacoco by jacoco.
the class StructuredLockingTest method assertStructuredLocking.
private void assertStructuredLocking(String owner, MethodNode mn) throws Exception {
Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new BasicInterpreter()) {
@Override
protected Frame<BasicValue> newFrame(int nLocals, int nStack) {
return new LockFrame(nLocals, nStack);
}
@Override
protected Frame<BasicValue> newFrame(Frame<? extends BasicValue> src) {
return new LockFrame(src);
}
};
Frame<BasicValue>[] frames = analyzer.analyze(owner, mn);
// Make sure no locks are left when method exits:
for (int i = 0; i < frames.length; i++) {
AbstractInsnNode insn = mn.instructions.get(i);
switch(insn.getOpcode()) {
case Opcodes.IRETURN:
case Opcodes.LRETURN:
case Opcodes.FRETURN:
case Opcodes.DRETURN:
case Opcodes.ARETURN:
case Opcodes.RETURN:
((LockFrame) frames[i]).assertNoLock("Exit with lock");
break;
case Opcodes.ATHROW:
List<TryCatchBlockNode> handlers = analyzer.getHandlers(i);
if (handlers == null || handlers.isEmpty()) {
((LockFrame) frames[i]).assertNoLock("Exit with lock");
}
break;
}
}
// Only instructions protected by a catch-all handler can hold locks:
for (int i = 0; i < frames.length; i++) {
AbstractInsnNode insn = mn.instructions.get(i);
if (insn.getOpcode() > 0) {
boolean catchAll = false;
List<TryCatchBlockNode> handlers = analyzer.getHandlers(i);
if (handlers != null) {
for (TryCatchBlockNode node : handlers) {
catchAll |= node.type == null;
}
}
if (!catchAll) {
((LockFrame) frames[i]).assertNoLock("No handlers for insn with lock");
}
}
}
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project openj9 by eclipse.
the class ClassFileCompare method compareTryCatchBlocks.
private void compareTryCatchBlocks(MethodNode method1, MethodNode method2) {
if (nullCheck(method1.tryCatchBlocks, method2.tryCatchBlocks, "Try-catch blocks (" + method1.name + ")")) {
return;
}
/*
* Copy and sort try-catch blocks by scope and type
*/
@SuppressWarnings("unchecked") List<TryCatchBlockNode> tryCatchBlocks1 = new ArrayList<>(method1.tryCatchBlocks);
@SuppressWarnings("unchecked") List<TryCatchBlockNode> tryCatchBlocks2 = new ArrayList<>(method2.tryCatchBlocks);
Collections.sort(tryCatchBlocks1, tryCatchBlockComparatorFor(method1));
Collections.sort(tryCatchBlocks2, tryCatchBlockComparatorFor(method2));
/*
* Compare try-catch blocks
*/
if (tryCatchBlocks1.size() != tryCatchBlocks2.size()) {
reportDifference("Try-catch blocks (" + method1.name + ") differ: " + tryCatchBlocks1.size() + ", " + tryCatchBlocks2.size());
} else {
Iterator<TryCatchBlockNode> iter = tryCatchBlocks1.iterator();
for (TryCatchBlockNode tryCatchBlock2 : tryCatchBlocks2) {
TryCatchBlockNode tryCatchBlock1 = iter.next();
compare(tryCatchBlock1.type, tryCatchBlock2.type, "Try-catch block (" + method1.name + ") type");
compare(method1, tryCatchBlock1.start, method2, tryCatchBlock2.start, "Try-catch block scope (" + method1.name + ") starts");
compare(method1, tryCatchBlock1.end, method2, tryCatchBlock2.end, "Try-catch block scope (" + method1.name + ") ends");
compare(method1, tryCatchBlock1.handler, method2, tryCatchBlock2.handler, "Try-catch block scope (" + method1.name + ") handlers");
}
}
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project soot by Sable.
the class AsmMethodSource method getBody.
@Override
public Body getBody(SootMethod m, String phaseName) {
if (!m.isConcrete())
return null;
JimpleBody jb = Jimple.v().newBody(m);
/* initialize */
int nrInsn = instructions.size();
nextLocal = maxLocals;
locals = new HashMap<Integer, Local>(maxLocals + (maxLocals / 2));
labels = ArrayListMultimap.create(4, 1);
units = new HashMap<AbstractInsnNode, Unit>(nrInsn);
frames = new HashMap<AbstractInsnNode, StackFrame>(nrInsn);
trapHandlers = ArrayListMultimap.create(tryCatchBlocks.size(), 1);
body = jb;
/* retrieve all trap handlers */
for (TryCatchBlockNode tc : tryCatchBlocks) trapHandlers.put(tc.handler, Jimple.v().newStmtBox(null));
/* convert instructions */
try {
convert();
} catch (Throwable t) {
throw new RuntimeException("Failed to convert " + m, t);
}
/* build body (add units, locals, traps, etc.) */
emitLocals();
emitTraps();
emitUnits();
/* clean up */
locals = null;
labels = null;
units = null;
stack = null;
frames = null;
body = null;
// Make sure to inline patterns of the form to enable proper variable
// splitting and type assignment:
// a = new A();
// goto l0;
// l0:
// b = (B) a;
// return b;
castAndReturnInliner.transform(jb);
try {
PackManager.v().getPack("jb").apply(jb);
} catch (Throwable t) {
throw new RuntimeException("Failed to apply jb to " + m, t);
}
return jb;
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project cassandra by apache.
the class MonitorMethodTransformer method writeInnerTryCatchSynchronized.
// alternative approach (with writeOuterUnsynchronized)
@SuppressWarnings("unused")
void writeInnerTryCatchSynchronized() {
access |= Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_SYNTHETIC;
name = baseName + "$catch";
Label start = new Label();
Label normal = new Label();
Label except = new Label();
Label end = new Label();
reset(start, end);
// must load self or class onto stack, and return value (if any)
maxStack = Math.max(maxLocalParams, returnCode == Opcodes.RETURN ? 1 : 2);
++maxLocals;
tryCatchBlocks.add(new TryCatchBlockNode(getLabelNode(start), getLabelNode(normal), getLabelNode(except), null));
instructions.add(getLabelNode(start));
int invokeCode = loadParamsAndReturnInvokeCode();
instructions.add(new MethodInsnNode(invokeCode, className, baseName + "$unsync", desc));
instructions.add(getLabelNode(normal));
invokePreMonitorExit();
instructions.add(new InsnNode(returnCode()));
instructions.add(getLabelNode(except));
instructions.add(new FrameNode(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }));
instructions.add(new IntInsnNode(Opcodes.ASTORE, maxLocalParams));
invokePreMonitorExit();
instructions.add(new IntInsnNode(Opcodes.ALOAD, maxLocalParams));
instructions.add(new InsnNode(Opcodes.ATHROW));
instructions.add(getLabelNode(end));
methodWriterSink.writeSyntheticMethod(MONITOR, this);
}
Aggregations