Skip to content

Commit

Permalink
Merge pull request #3 from spgroup/master
Browse files Browse the repository at this point in the history
Bring Master fork
  • Loading branch information
Rafael Mota Alves authored Jun 30, 2020
2 parents d555802 + f73785a commit 952f411
Show file tree
Hide file tree
Showing 39 changed files with 1,742 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist: trusty

language: java

jdk:
- oraclejdk8
4 changes: 1 addition & 3 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ Current supported algorithms:

To build the project, you will need Maven and Java 8 (or higher).

First, build and install the [svfa-scala](https://github.com/rbonifacio/svfa-scala) library.

After that, run the following commands:
Clone the repository and than run the following commmand.

```SHELL
mvn clean install -DskipTests
Expand Down
18 changes: 16 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@
<modelVersion>4.0.0</modelVersion>
<groupId>br.unb.cic</groupId>
<artifactId>soot-analysis</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>

<repositories>
<repository>
<id>spgroup</id>
<name>SPG Maven Repository (fork of the soot project)</name>
<url>https://maven.pkg.github.com/spgroup/soot/</url>
</repository>
<repository>
<id>rbonifacio</id>
<name>Temporary repository for the SVFA library</name>
<url>https://maven.pkg.github.com/rbonifacio/svfa-scala/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>br.unb.cic</groupId>
<artifactId>svfa-scala_2.12</artifactId>
<version>0.0.4-SNAPSHOT</version>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import br.unb.cic.analysis.model.Statement;
import soot.Local;
import soot.jimple.internal.JInstanceFieldRef;

import java.util.Objects;

Expand All @@ -12,17 +13,27 @@
public class DataFlowAbstraction {

private Local local;
private JInstanceFieldRef localInstanceField;
private Statement stmt;

public DataFlowAbstraction(Local local, Statement stmt) {
this.local = local;
this.stmt = stmt;
}

public DataFlowAbstraction(JInstanceFieldRef localInstanceField, Statement stmt) {
this.localInstanceField = localInstanceField;
this.stmt = stmt;
}

public Local getLocal() {
return local;
}

public JInstanceFieldRef getJInstanceFieldRef() {
return localInstanceField;
}

public Statement getStmt() {
return stmt;
}
Expand Down
143 changes: 143 additions & 0 deletions src/main/java/br/unb/cic/analysis/df/OverridingAssignmentAnalysis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package br.unb.cic.analysis.df;

import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import br.unb.cic.analysis.model.Conflict;
import br.unb.cic.analysis.model.Statement;
import soot.Body;
import soot.Local;
import soot.Unit;
import soot.ValueBox;
import soot.jimple.internal.JArrayRef;
import soot.jimple.internal.JInstanceFieldRef;
import soot.toolkits.scalar.ArraySparseSet;
import soot.toolkits.scalar.FlowSet;

import java.util.ArrayList;
import java.util.List;

public class OverridingAssignmentAnalysis extends ReachDefinitionAnalysis {

/**
* Constructor of the DataFlowAnalysis class.
* <p>
* According to the SOOT architecture, the constructor for a
* flow analysis must receive as an argument a graph, set up
* essential information and call the doAnalysis method of the
* super class.
*
* @param definition a set of conflict definitions.
*/
public OverridingAssignmentAnalysis(Body methodBody, AbstractMergeConflictDefinition definition) {
super(methodBody, definition);
}

@Override
protected FlowSet<DataFlowAbstraction> gen(Unit u, FlowSet<DataFlowAbstraction> in) {
FlowSet<DataFlowAbstraction> res = new ArraySparseSet<>();
if (isSourceStatement(u) || isSinkStatement(u)) {
u.getUseAndDefBoxes().stream().filter(v -> v.getValue() instanceof Local).forEach(v -> {
Statement stmt = isSourceStatement(u) ? findSourceStatement(u) : findSinkStatement(u);
res.add(new DataFlowAbstraction((Local) v.getValue(), stmt));
});
} else if (u.getDefBoxes().size() > 0) {

u.getDefBoxes().stream().filter(v -> v.getValue() instanceof Local).forEach(v -> {
String localName = getLocalName((Local) v.getValue());

for (DataFlowAbstraction defsIn: in){
String defInName = getLocalName(defsIn.getLocal());
//if u not in IN, then add it
if (!defInName.equals(localName)){
res.add(new DataFlowAbstraction(defsIn.getLocal(), defsIn.getStmt())); //update an element in IN
break; //Do not necessary check others elements
}
}
});
}
return res;
}


@Override
protected void detectConflict(FlowSet<DataFlowAbstraction> in, Unit u){
if (!(isSinkStatement(u) || isSourceStatement(u))){
return;
}
List<DataFlowAbstraction> left = new ArrayList<>();
List<DataFlowAbstraction> right = new ArrayList<>();

u.getUseAndDefBoxes().stream().filter(v -> v.getValue() instanceof Local).forEach(v -> {
String localName = getLocalName((Local) v.getValue());
for (DataFlowAbstraction filterIn: in){
String inName = getLocalName(filterIn.getLocal());

if (filterIn.getStmt().getType().equals(Statement.Type.SOURCE) && inName.equals(localName)){
left.add(filterIn);
}else if (filterIn.getStmt().getType().equals(Statement.Type.SINK) && inName.equals(localName)){
right.add(filterIn);
}
}
});

if(isSinkStatement(u)) {
checkConflicts(u, left);
}else if (isSourceStatement(u)){
checkConflicts(u, right);
}
}

protected void checkConflicts(Unit u, List<DataFlowAbstraction> statements){
for (DataFlowAbstraction statement : statements) {
if (statementEquals(statement, u)) {
Conflict c = new Conflict(statement.getStmt(), findStatement(u));
Collector.instance().addConflict(c);
}
}
}

@Override
protected void flowThrough(FlowSet<DataFlowAbstraction> in, Unit u, FlowSet<DataFlowAbstraction> out) {
detectConflict(in, u);
FlowSet<DataFlowAbstraction> temp = new ArraySparseSet<>();

FlowSet<DataFlowAbstraction> killSet = new ArraySparseSet<>();
for(DataFlowAbstraction item : in) {
if (statementEquals(item, u)){
killSet.add(item);
}
}
in.difference(killSet, temp);
temp.union(gen(u, in), out);
}

private String getLocalName(Local local){
return local.getName().split("#")[0];
}

private boolean statementEquals(DataFlowAbstraction statement, Unit u){

String statementName = getLocalName(statement.getLocal());
for (ValueBox local : u.getDefBoxes()) {
String localName = "";
for (ValueBox field : statement.getStmt().getUnit().getDefBoxes()) {
if (local.getValue() instanceof JInstanceFieldRef) {
statementName = field.getValue().toString();
localName = local.getValue().toString();
}else if (local.getValue() instanceof JArrayRef) {
if (!(isSinkStatement(u) || isSourceStatement(u))){
return false;
}
statementName = ((field.getValue()) instanceof JArrayRef)
? (((JArrayRef) field.getValue()).getBaseBox().getValue()).toString()
: field.getValue().toString();
localName = (((JArrayRef) local.getValue()).getBaseBox().getValue()).toString();
}
}
if (localName.equals("") && local.getValue() instanceof Local) {
localName = getLocalName((Local) local.getValue());
}
return statementName.contains(localName);
}
return false;
}
}
Loading

0 comments on commit 952f411

Please sign in to comment.