Commit 16ae23c0 authored by Lukáš Marek's avatar Lukáš Marek

Moved after throw region marking to the marker

Warn: HEAD is not working
parent f53e9383
......@@ -27,6 +27,7 @@ import ch.usi.dag.disl.exception.DiSLIOException;
import ch.usi.dag.disl.exception.DynamicInfoException;
import ch.usi.dag.disl.exception.InitException;
import ch.usi.dag.disl.exception.ManifestInfoException;
import ch.usi.dag.disl.exception.MarkerException;
import ch.usi.dag.disl.exception.ProcessorException;
import ch.usi.dag.disl.exception.ReflectionException;
import ch.usi.dag.disl.exception.StaticContextGenException;
......@@ -195,7 +196,7 @@ public class DiSL {
*/
private boolean instrumentMethod(ClassNode classNode, MethodNode methodNode)
throws ReflectionException, StaticContextGenException,
ProcessorException, DynamicInfoException {
ProcessorException, DynamicInfoException, MarkerException {
// skip abstract methods
if ((methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
......
package ch.usi.dag.disl.marker;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.exception.MarkerException;
import ch.usi.dag.disl.snippet.Shadow;
import ch.usi.dag.disl.snippet.Snippet;
......@@ -17,6 +20,9 @@ public abstract class AbstractMarker implements Marker {
private AbstractInsnNode start;
private List<AbstractInsnNode> ends;
private AbstractInsnNode afterThrowStart;
private AbstractInsnNode afterThrowEnd;
public AbstractInsnNode getStart() {
return start;
......@@ -25,10 +31,26 @@ public abstract class AbstractMarker implements Marker {
public List<AbstractInsnNode> getEnds() {
return ends;
}
public AbstractInsnNode getAfterThrowStart() {
return afterThrowStart;
}
public AbstractInsnNode getAfterThrowEnd() {
return afterThrowEnd;
}
public void setStart(AbstractInsnNode start) {
this.start = start;
}
public void setAfterThrowStart(AbstractInsnNode afterThrowStart) {
this.afterThrowStart = afterThrowStart;
}
public void setAfterThrowEnd(AbstractInsnNode afterThrowEnd) {
this.afterThrowEnd = afterThrowEnd;
}
public MarkedRegion(AbstractInsnNode start) {
this.start = start;
......@@ -49,11 +71,42 @@ public abstract class AbstractMarker implements Marker {
public void addExitPoint(AbstractInsnNode exitpoint) {
this.ends.add(exitpoint);
}
public boolean valid() {
return start != null && ends != null
&& afterThrowStart != null && afterThrowEnd != null;
}
public void computeAfterThrow(MethodNode methodNode) {
// set start
afterThrowStart = start;
// get end that is the latest in the method instructions
Set<AbstractInsnNode> endsSet = new HashSet<AbstractInsnNode>(ends);
AbstractInsnNode instr = methodNode.instructions.getLast();
while(instr != null) {
if(endsSet.contains(instr)) {
afterThrowEnd = instr;
break;
}
instr.getPrevious();
}
}
public void skipBranchesAtTheEnds() {
// TODO ! markers
}
}
@Override
public List<Shadow> mark(ClassNode classNode, MethodNode methodNode,
Snippet snippet) {
Snippet snippet) throws MarkerException {
// use simplified interface
List<MarkedRegion> regions = mark(methodNode);
......@@ -63,8 +116,15 @@ public abstract class AbstractMarker implements Marker {
// convert marked regions to shadows
for (MarkedRegion mr : regions) {
if(! mr.valid()) {
throw new MarkerException("Marker " + this.getClass()
+ " produced invalid MarkedRegion (some MarkedRegion" +
" fields where not set)");
}
result.add(new Shadow(classNode, methodNode, snippet,
mr.getStart(), mr.getEnds()));
mr.getStart(), mr.getEnds(), mr.getAfterThrowStart(),
mr.getAfterThrowEnd()));
}
return result;
......
......@@ -5,10 +5,12 @@ import java.util.List;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.exception.MarkerException;
import ch.usi.dag.disl.snippet.Shadow;
import ch.usi.dag.disl.snippet.Snippet;
public interface Marker {
public List<Shadow> mark(ClassNode classNode, MethodNode methodNode, Snippet snippet);
public List<Shadow> mark(ClassNode classNode, MethodNode methodNode,
Snippet snippet) throws MarkerException;
}
......@@ -12,19 +12,26 @@ public class Shadow {
protected ClassNode classNode;
protected MethodNode methodNode;
protected Snippet snippet;
private AbstractInsnNode regionStart;
private List<AbstractInsnNode> regionEnds;
public Shadow(ClassNode classNode, MethodNode methodNode,
Snippet snippet, AbstractInsnNode regionStart, List<AbstractInsnNode> regionEnds) {
private AbstractInsnNode afterThrowStart;
private AbstractInsnNode afterThrowEnd;
public Shadow(ClassNode classNode, MethodNode methodNode, Snippet snippet,
AbstractInsnNode regionStart, List<AbstractInsnNode> regionEnds,
AbstractInsnNode afterThrowStart, AbstractInsnNode afterThrowEnd) {
super();
this.classNode = classNode;
this.methodNode = methodNode;
this.snippet = snippet;
this.regionStart = regionStart;
this.regionEnds = regionEnds;
this.afterThrowStart = afterThrowStart;
this.afterThrowEnd = afterThrowEnd;
}
// special constructor for caching support
public Shadow(Shadow sa) {
......@@ -54,4 +61,12 @@ public class Shadow {
public List<AbstractInsnNode> getRegionEnds() {
return regionEnds;
}
public AbstractInsnNode getAfterThrowStart() {
return afterThrowStart;
}
public AbstractInsnNode getAfterThrowEnd() {
return afterThrowEnd;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment