Commit f9d5c941 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

introduction of theaded SDG

- ICFG.Builder can avoid repeated building CFGs and call/classGraph if they are provided.
- TSDG based on the TPDG (PPDG) and ICFG.
- New type of arc: InterferenceDependencyArc
parent b3860caf
Loading
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.arcs;

import es.upv.mist.slicing.arcs.pdg.DataDependencyArc;
import es.upv.mist.slicing.nodes.VariableAction;

public class InterferenceDependencyArc extends DataDependencyArc {
    public InterferenceDependencyArc(VariableAction sourceVar, VariableAction targetVar) {
        super(sourceVar, targetVar);
    }
}
+21 −3
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import static es.upv.mist.slicing.util.SingletonCollector.toSingleton;
public class ICFG extends Graph implements Buildable<NodeList<CompilationUnit>> {

    protected final Map<CallableDeclaration<?>, CFG> cfgMap = ASTUtils.newIdentityHashMap();
    protected CallGraph callGraph;
    protected boolean built = false;

    public void addControlFlowArc(GraphNode<?> from, GraphNode<?> to) {
@@ -46,9 +45,17 @@ public class ICFG extends Graph implements Buildable<NodeList<CompilationUnit>>
    }

    @Override
    public void build(NodeList<CompilationUnit> arg) {
    public void build(NodeList<CompilationUnit> nodeList) {
        if (built) return;
        new Builder().build(nodeList);
        built = true;
    }

    /** Builds the ICFG on a pre-built set of CFGs and their call graph. */
    public void build(Map<CallableDeclaration<?>, CFG> cfgMap, CallGraph callGraph) {
        if (built) return;
        new Builder().build(arg);
        this.cfgMap.putAll(cfgMap);
        new Builder().build(callGraph);
        built = true;
    }

@@ -58,11 +65,22 @@ public class ICFG extends Graph implements Buildable<NodeList<CompilationUnit>>
    }

    public class Builder {
        protected CallGraph callGraph;

        public void build(NodeList<CompilationUnit> units) {
            createClassGraph(units);
            buildCFGs(units);
            createCallGraph(units);
            dataFlowAnalysis();
            buildFromCFGs();
        }

        public void build(CallGraph callGraph) {
            this.callGraph = callGraph;
            buildFromCFGs();
        }

        protected void buildFromCFGs() {
            copyCFGs();
            expandCalls();
            joinCFGs();
+14 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.threaded;

import es.upv.mist.slicing.graphs.augmented.PPDG;

public class TPDG extends PPDG {
    @Override
    protected Builder createBuilder() {
        return new Builder();
    }

    public class Builder extends PPDG.Builder {

    }
}
+51 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.threaded;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.NodeList;
import es.upv.mist.slicing.arcs.InterferenceDependencyArc;
import es.upv.mist.slicing.graphs.augmented.ASDG;
import es.upv.mist.slicing.graphs.cfg.CFG;
import es.upv.mist.slicing.graphs.icfg.ICFG;
import es.upv.mist.slicing.graphs.pdg.PDG;
import es.upv.mist.slicing.nodes.GraphNode;
import es.upv.mist.slicing.nodes.VariableAction;

public class TSDG extends ASDG {
    protected final ICFG icfg;

    public TSDG() {
        this.icfg = new ICFG();
    }

    public TSDG(ICFG icfg) {
        this.icfg = icfg;
    }

    public void addInterferenceDependencyArc(VariableAction source, VariableAction target) {
        GraphNode<?> src = source.getGraphNode();
        GraphNode<?> tgt = target.getGraphNode();
        addEdge(src, tgt, new InterferenceDependencyArc(source, target));
    }

    @Override
    protected ASDG.Builder createBuilder() {
        return new Builder();
    }

    public class Builder extends ASDG.Builder {
        public void build(NodeList<CompilationUnit> nodeList) {
            super.build(nodeList);
            icfg.build(cfgMap, callGraph);
            computeInterferences();
        }

        @Override
        protected PDG createPDG(CFG cfg) {
            return new TPDG();
        }

        protected void computeInterferences() {
            // TODO: actually compute
        }
    }
}
+31 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.threaded;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.NodeList;
import es.upv.mist.slicing.cli.SDGLog;
import es.upv.mist.slicing.graphs.icfg.ICFGLog;
import es.upv.mist.slicing.utils.StaticTypeSolver;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class TSDGTest {
    public static void main(String[] args) throws IOException {
        StaticJavaParser.getConfiguration().setAttributeComments(false);
        StaticTypeSolver.addTypeSolverJRE();

        File file = new File(Thread.currentThread().getContextClassLoader().getResource("Threads.java").getPath());
        NodeList<CompilationUnit> units = new NodeList<>();
        try {
            units.add(StaticJavaParser.parse(file));
        } catch (FileNotFoundException e) {
            System.out.println("No se encontró el archivo");
        }
        TSDG sdg = new TSDG();
        sdg.build(units);
        new SDGLog(sdg).generateImages();
        new ICFGLog(sdg.icfg).generateImages();
    }
}
Loading