Skip to content

Commit

Permalink
Merge modification
Browse files Browse the repository at this point in the history
  • Loading branch information
galilasmb committed Apr 1, 2021
1 parent 7d11b17 commit 6be6d5e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 49 deletions.
7 changes: 3 additions & 4 deletions src/main/java/br/unb/cic/analysis/df/Collector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import br.unb.cic.analysis.model.Conflict;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JInstanceFieldRef;

import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -12,7 +11,7 @@
class Collector {

private Set<Conflict> conflicts;
private Set<HashMap<String, JInstanceFieldRef>> instanceFieldDictionary;
private Set<HashMap<String, InstanceFieldRef>> instanceFieldDictionary;
private Set<HashMap<String, StaticFieldRef>> staticFieldDictionary;
private static Collector instance;

Expand All @@ -29,11 +28,11 @@ public static Collector instance() {
return instance;
}

public Set<HashMap<String, JInstanceFieldRef>> getHashInstanceField() {
public Set<HashMap<String, InstanceFieldRef>> getHashInstanceField() {
return instanceFieldDictionary;
}

public void addHashInstanceField(HashMap<String, JInstanceFieldRef> hash) {
public void addHashInstanceField(HashMap<String, InstanceFieldRef> hash) {
instanceFieldDictionary.add(hash);
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import br.unb.cic.analysis.model.Statement;
import soot.Local;
import soot.Value;
import soot.jimple.InstanceFieldRef;
import soot.jimple.InvokeStmt;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JInstanceFieldRef;
import soot.jimple.internal.JInvokeStmt;

import java.util.*;

Expand All @@ -16,13 +16,13 @@
public class DataFlowAbstraction {

private Local local;
private JInstanceFieldRef localField;
private InstanceFieldRef localField;
private StaticFieldRef localStaticRef;
private JInvokeStmt methodCall;
private InvokeStmt methodCall;
private Statement stmt;
private Value value;

public DataFlowAbstraction(JInvokeStmt methodCall, Statement stmt){
public DataFlowAbstraction(InvokeStmt methodCall, Statement stmt){
this.methodCall = methodCall;
this.stmt = stmt;
}
Expand All @@ -37,7 +37,7 @@ public DataFlowAbstraction(Local local, Statement stmt) {
this.stmt = stmt;
}

public DataFlowAbstraction(JInstanceFieldRef localField, Statement stmt) {
public DataFlowAbstraction(InstanceFieldRef localField, Statement stmt) {
this.localField = localField;
this.stmt = stmt;
}
Expand All @@ -47,11 +47,11 @@ public DataFlowAbstraction(StaticFieldRef localStaticRef, Statement stmt) {
this.stmt = stmt;
}

public JInvokeStmt getMethodCall() {
public InvokeStmt getMethodCall() {
return methodCall;
}

public void setMethodCall(JInvokeStmt methodCall) {
public void setMethodCall(InvokeStmt methodCall) {
this.methodCall = methodCall;
}

Expand All @@ -71,7 +71,7 @@ public void setValue(Value value) {
this.value = value;
}

public JInstanceFieldRef getFieldRef() {
public InstanceFieldRef getFieldRef() {
return localField;
}
public Statement getStmt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import br.unb.cic.analysis.model.Conflict;
import br.unb.cic.analysis.model.Statement;
import soot.*;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.*;
import soot.jimple.*;
import soot.toolkits.scalar.ArraySparseSet;
import soot.toolkits.scalar.FlowSet;

Expand Down Expand Up @@ -77,17 +76,17 @@ protected FlowSet<DataFlowAbstraction> gen(Unit u, FlowSet<DataFlowAbstraction>

if (isLeftStatement(u) || isRightStatement(u)) {
Statement stmt = getStatementAssociatedWithUnit(u);
if (u instanceof JInvokeStmt){
res.add(new DataFlowAbstraction(((JInvokeStmt) u), stmt));
if (u instanceof InvokeStmt){
res.add(new DataFlowAbstraction((InvokeStmt) u, stmt));
}
u.getDefBoxes().forEach(valueBox -> {
if (valueBox.getValue() instanceof Local){
res.add(new DataFlowAbstraction((Local) valueBox.getValue(), stmt));
} else if (valueBox.getValue() instanceof JArrayRef){
} else if (valueBox.getValue() instanceof ArrayRef){
res.add(new DataFlowAbstraction(getArrayName(valueBox), stmt));
} else if (valueBox.getValue() instanceof StaticFieldRef) {
res.add(new DataFlowAbstraction((StaticFieldRef) valueBox.getValue(), stmt));
} else if (valueBox.getValue() instanceof JInstanceFieldRef){
} else if (valueBox.getValue() instanceof InstanceFieldRef){
res.add(new DataFlowAbstraction(getFieldName(valueBox), stmt));
}
});
Expand Down Expand Up @@ -131,7 +130,7 @@ private void checkConflicts(Unit u, List<DataFlowAbstraction> potentialConflicti
}
}
//Report conflict when changing the same return
if (u instanceof JReturnStmt && isLeftStatement(u) && isRightStatement(u)){
if (u instanceof ReturnStmt && isLeftStatement(u) && isRightStatement(u)){
reportConflict(findStatement(u), u);
}
}
Expand All @@ -148,15 +147,15 @@ private void reportConflict(Statement left, Unit right){
private boolean abstractionVariableIsInIUnitDefBoxes(DataFlowAbstraction dataFlowAbstraction, Unit u) {
for (ValueBox valueBox : u.getDefBoxes()) {
Object value = valueBox.getValue();
if (value instanceof JInstanceFieldRef && dataFlowAbstraction.getFieldRef()!=null) {
if (value instanceof InstanceFieldRef && dataFlowAbstraction.getFieldRef()!=null) {
return dataFlowAbstraction.getFieldRef().toString().equals(getFieldsChain(value.toString()));
} else if (value instanceof JArrayRef && value.toString().contains("$stack")) { // If contain $stack, contain a array chain
} else if (value instanceof ArrayRef && value.toString().contains("$stack")) { // If contain $stack, contain a array chain
return getVarNameFromAbstraction(dataFlowAbstraction).equals(getArrayChain(valueBox));
} else{
return getVarNameFromAbstraction(dataFlowAbstraction).equals(getVarNameFromValueBox(valueBox));
}
}
if (u instanceof JInvokeStmt){
if (u instanceof InvokeStmt){
return compareMethodAndObjectName(dataFlowAbstraction, u);
}
return false;
Expand All @@ -166,7 +165,7 @@ private boolean abstractionVariableIsInIUnitDefBoxes(DataFlowAbstraction dataFlo
* Compares whether left and right called the same object and method
*/
private boolean compareMethodAndObjectName(DataFlowAbstraction dataFlowAbstraction, Unit u){
if ( !(dataFlowAbstraction.getStmt().getUnit() instanceof JInvokeStmt)){
if ( !(dataFlowAbstraction.getStmt().getUnit() instanceof InvokeStmt)){
return false;
}
String objectNameFromUnit = getObjectName(u);
Expand All @@ -175,7 +174,7 @@ private boolean compareMethodAndObjectName(DataFlowAbstraction dataFlowAbstracti
String objectNameFromAbstraction = getObjectName(dataFlowAbstraction.getStmt().getUnit());
String methodStatementFromAbstraction = getMethodName(dataFlowAbstraction.getStmt().getUnit());

String methodName = (((JInvokeStmt) u).getInvokeExpr()).getMethodRef().getName();
String methodName = (((InvokeStmt) u).getInvokeExpr()).getMethodRef().getName();

if ((objectNameFromUnit+""+methodStatementFromUnit).equals(objectNameFromAbstraction+""+methodStatementFromAbstraction) && !methodName.startsWith("get")){
return true;
Expand All @@ -187,8 +186,8 @@ private boolean compareMethodAndObjectName(DataFlowAbstraction dataFlowAbstracti
* Returns a String containing the name of the object given a Unit
*/
private String getObjectName(Unit u){
if (u instanceof JVirtualInvokeExpr){
return ((JVirtualInvokeExpr)((JInvokeStmt) u).getInvokeExpr()).getBase().toString();
if (u instanceof VirtualInvokeExpr){
return ((VirtualInvokeExpr)((InvokeStmt) u).getInvokeExpr()).getBase().toString();
}
return "";
}
Expand All @@ -197,7 +196,7 @@ private String getObjectName(Unit u){
* Returns a String containing the name of the method called given a Unit
*/
private String getMethodName(Unit u){
return (((JInvokeStmt) u).getInvokeExpr()).getMethodRef().toString();
return (((InvokeStmt) u).getInvokeExpr()).getMethodRef().toString();
}

/*
Expand All @@ -224,8 +223,8 @@ private String getVarNameFromValueBox(ValueBox valueBox) {
varNameValueBox = getLocalName((Local) valueBox.getValue());
} else if (valueBox.getValue() instanceof StaticFieldRef) {
varNameValueBox = getStaticName((StaticFieldRef) valueBox.getValue());
} else if (valueBox.getValue() instanceof JArrayRef) {
varNameValueBox = getArrayRefName((JArrayRef) valueBox.getValue()).toString();
} else if (valueBox.getValue() instanceof ArrayRef) {
varNameValueBox = getArrayRefName((ArrayRef) valueBox.getValue()).toString();
}
return varNameValueBox;
}
Expand Down Expand Up @@ -256,15 +255,15 @@ private String getLocalName(Local local) {
* of the variable used to assign an array;
* e.g: int[] arr = {0, 1}; --> "arr"
*/
private Value getArrayRefName(JArrayRef arrayRef) {
private Value getArrayRefName(ArrayRef arrayRef) {
return arrayRef.getBaseBox().getValue();
}

/*
* If it's a JInstanceField, returns your complete name from the hashMapJInstanceField
* If it's a InstanceField, returns your complete name from the hashMapInstanceField
*/
private JInstanceFieldRef getFieldName(ValueBox valueBox){
JInstanceFieldRef fieldValue = (JInstanceFieldRef) valueBox.getValue();
private InstanceFieldRef getFieldName(ValueBox valueBox){
InstanceFieldRef fieldValue = (InstanceFieldRef) valueBox.getValue();
if (fieldValue.toString().contains("$stack")) {
String chainName = getFieldsChain(valueBox.getValue().toString()); //return the complete chain with the FieldRef
((Local) fieldValue.getBase()).setName(chainName.replace("."+fieldValue.getField().toString(), "")); //remove the double FieldRef from jInstanceFieldValue
Expand All @@ -277,7 +276,7 @@ private JInstanceFieldRef getFieldName(ValueBox valueBox){
* Else, returns the Array Name
*/
private Local getArrayName(ValueBox valueBox){
Local localName = (Local) getArrayRefName((JArrayRef) valueBox.getValue());
Local localName = (Local) getArrayRefName((ArrayRef) valueBox.getValue());
if (localName.toString().contains("$stack")) {
localName.setName(getArrayChain(valueBox));
}
Expand All @@ -294,7 +293,7 @@ private String getStaticName(StaticFieldRef staticField) {
}

/*
* Returns the name of the JArrayRef
* Returns the name of the ArrayRef
* The Jimple code is divided in others units
* Example:
* static int[] y;
Expand All @@ -309,7 +308,7 @@ private String getStaticName(StaticFieldRef staticField) {
* $stack2[0] -> $stack2 = <className: int[] y> -> (STOP) -> Result: <className: int[] y>
*/
private String getArrayChain(ValueBox valueBox){
String nextKey = ((JArrayRef) valueBox.getValue()).getBase().toString();
String nextKey = ((ArrayRef) valueBox.getValue()).getBase().toString();
for (HashMap<String, StaticFieldRef> auxMap : getHashMapStatic()) {
for (String mapKey : auxMap.keySet()) {
if (mapKey.equals(nextKey)) {
Expand Down Expand Up @@ -338,15 +337,15 @@ private String getArrayChain(ValueBox valueBox){
* InitialKey($stack8.a) -> nextKey ($stack8) -> nextKey ($stack3) -> object.b has no nextKey (STOP) -> Return object chain -> Return: object.b.a.a
*/
private String getFieldsChain(String nextKey){
List<HashMap<String, JInstanceFieldRef>> auxValuesHashMap = new ArrayList<>();
auxValuesHashMap.addAll(getHashMapJInstanceField());
List<HashMap<String, InstanceFieldRef>> auxValuesHashMap = new ArrayList<>();
auxValuesHashMap.addAll(getHashMapInstanceField());

//If nextKey not contain $stack is because simple key
if (!(nextKey.contains("$stack"))){
return nextKey;
}

JInstanceFieldRef currentField = null;
InstanceFieldRef currentField = null;

//The second position is the field called
String currentUniqueKey = "<"+nextKey.split(".<")[1];
Expand All @@ -360,7 +359,7 @@ private String getFieldsChain(String nextKey){

Iterator iterator = auxValuesHashMap.iterator();
while (iterator.hasNext() && !isNextKey){
HashMap<String, JInstanceFieldRef> auxMap = (HashMap<String, JInstanceFieldRef>) iterator.next();
HashMap<String, InstanceFieldRef> auxMap = (HashMap<String, InstanceFieldRef>) iterator.next();
for (String mapKey : auxMap.keySet()) {
if (mapKey.equals(nextKey)) {
currentField = auxMap.get(mapKey);
Expand All @@ -386,11 +385,11 @@ private String getFieldsChain(String nextKey){


/*
* Generates the dictionary with the UseBoxes instances of JInstanceFieldRef or StaticFieldRef
* Generates the dictionary with the UseBoxes instances of InstanceFieldRef or StaticFieldRef
*/
public void generateFieldDictionary(Unit u){
for (ValueBox valueBox: u.getUseBoxes()) {
if (valueBox.getValue() instanceof JInstanceFieldRef) {
if (valueBox.getValue() instanceof InstanceFieldRef) {
generateClassFieldDictionary(getStatementAssociatedWithUnit(u));
}else if (valueBox.getValue() instanceof StaticFieldRef) {
generateStaticRefDictionary(u, valueBox);
Expand All @@ -412,18 +411,18 @@ private void generateStaticRefDictionary(Unit u, ValueBox valueBox){
}

/*
* Generates a dictionary to JInstanceFieldRef
* Generates a dictionary to InstanceFieldRef
*/
private void generateClassFieldDictionary(Statement stmt){
HashMap<String, JInstanceFieldRef> auxHashMap = new HashMap<>();
HashMap<String, InstanceFieldRef> auxHashMap = new HashMap<>();
StringBuilder strKey = new StringBuilder();
for (ValueBox valueBoxKey : stmt.getUnit().getDefBoxes()) {
strKey.append(valueBoxKey.getValue().toString());
}
JInstanceFieldRef currentFieldRef = null;
InstanceFieldRef currentFieldRef = null;
for (ValueBox catchRef : stmt.getUnit().getUseBoxes()) {
if (catchRef.getValue() instanceof JInstanceFieldRef) {
currentFieldRef = (JInstanceFieldRef) catchRef.getValue();
if (catchRef.getValue() instanceof InstanceFieldRef) {
currentFieldRef = (InstanceFieldRef) catchRef.getValue();
auxHashMap.put(strKey.toString(), currentFieldRef);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Set<Conflict> getConflicts() {
return Collector.instance().getConflicts();
}

public Set<HashMap<String, JInstanceFieldRef>> getHashMapJInstanceField() {
public Set<HashMap<String, InstanceFieldRef>> getHashMapInstanceField() {
return Collector.instance().getHashInstanceField();
}

Expand Down

0 comments on commit 6be6d5e

Please sign in to comment.