Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias analysis #194

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
885fe71
add alias analysis
LukasKlenner May 2, 2024
49084fc
remove some empty lines in ParameterAlias
LukasKlenner Jun 13, 2024
390878a
remove unused code
LukasKlenner Jun 13, 2024
6ac9254
add compatible analyses information to ParameterAlias
LukasKlenner Jun 13, 2024
052ad9f
improve AliasSet implementation
LukasKlenner Jun 13, 2024
3d29630
merge related files into one file
LukasKlenner Jun 13, 2024
08537a0
fix formatting
LukasKlenner Jun 13, 2024
a90c721
add fixture for arrays
LukasKlenner Jun 13, 2024
464de44
use classHierarchy.isSubtypeOf for type compatibility check
LukasKlenner Jun 13, 2024
d197081
fix formatting
LukasKlenner Jun 13, 2024
b5ef3fa
add compatible analyses to ArrayAlias
LukasKlenner Jun 13, 2024
8d5cd2e
use reference equality in AliasEntity
LukasKlenner Jun 13, 2024
0e9212d
combine normal and line alias annotations
LukasKlenner Jun 14, 2024
62c4ac6
remove blank lines in fixtures
LukasKlenner Jun 14, 2024
86207cc
store old pointsToSet in analysisState
LukasKlenner Jun 17, 2024
115304a
try to fix formatting
LukasKlenner Jun 17, 2024
4a61249
try to fix formatting again
LukasKlenner Jun 17, 2024
e7d505e
Create new PDUVar class
maximilianruesch Jan 25, 2024
db776b2
move PDUVar to br package; apply further changes from upstream
LukasKlenner Aug 5, 2024
f4de876
use PUVar to represent AliasUVar
LukasKlenner Aug 5, 2024
0f04443
migrate alias analysis to PUVar
LukasKlenner Aug 5, 2024
64cbd81
Merge remote-tracking branch 'refs/remotes/origin/develop' into featu…
LukasKlenner Aug 5, 2024
b209462
fix package declaration in PDUVar
LukasKlenner Aug 5, 2024
cec1ecb
use (post)dominator tree to check whether an allocation site is insid…
LukasKlenner Aug 9, 2024
6d15ff5
add additional test cases for nested loops
LukasKlenner Aug 9, 2024
706cfa3
Merge remote-tracking branch 'origin/develop' into feature/alias-anal…
LukasKlenner Aug 9, 2024
390be8a
Cache the calculated dominator trees
LukasKlenner Aug 9, 2024
841dab6
throw exception when calculating dominator tree for unsupported metho…
LukasKlenner Aug 9, 2024
b3fd4e3
fix formatting
LukasKlenner Aug 9, 2024
93acfde
fix formatting again
LukasKlenner Aug 9, 2024
f32408d
fix typo in checkMustAlias
LukasKlenner Aug 9, 2024
901c59b
improve comment for in-loop check
LukasKlenner Aug 13, 2024
e607ccd
add tac-based postDominatorTree method to CFG class
LukasKlenner Aug 13, 2024
83179b3
convert dominatorTree methods in CFG to lazy vals to avoid multiple c…
LukasKlenner Aug 13, 2024
63c8a42
remove redundant caching of dominator trees in TacBasedAliasAnalysisS…
LukasKlenner Aug 13, 2024
ca1df0a
remove redundant Seq.empty in postDominatorTree method
LukasKlenner Aug 13, 2024
ea3e0e7
Merge branch 'develop' into feature/alias-analysis
errt Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.NoAlias;

import org.opalj.tac.fpcf.analyses.alias.AllocationSiteBasedAliasAnalysis;

public class ArrayAlias {

@NoAlias(reason = "no alias with array and uVar that is not stored to array",
lineNumber = 20,
secondLineNumber = 22,
analyses = {/*AllocationSiteBasedAliasAnalysis.class*/})
analyses = AllocationSiteBasedAliasAnalysis.class)
public static void notStoredToArray() {

Object[] arr = new Object[10];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.NoAlias;

import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;

public class FieldAlias {

@NoAlias(reason = "no alias for fields of different objects",
lineNumber = 20, fieldName = "field", fieldClass = FieldClass.class,
secondLineNumber = 21, secondFieldName = "field2", secondFieldClass = FieldClass.class)
secondLineNumber = 21, secondFieldName = "field2", secondFieldClass = FieldClass.class, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public void differentObjectsSameFields() {
FieldClass fc = new FieldClass();
FieldClass fc2 = new FieldClass();
Expand All @@ -23,7 +23,7 @@ public void differentObjectsSameFields() {

@NoAlias(reason = "no alias for different fields of the same object",
lineNumber = 32, fieldName = "field", fieldClass = FieldClass.class,
secondLineNumber = 33, secondFieldName = "field2", secondFieldClass = FieldClass.class)
secondLineNumber = 33, secondFieldName = "field2", secondFieldClass = FieldClass.class, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public void sameObjectDifferentField() {
FieldClass fc = new FieldClass();
fc.field = new Object();
Expand All @@ -35,7 +35,7 @@ public void sameObjectDifferentField() {

@NoAlias(reason = "no alias for different fields of different objects",
lineNumber = 46, fieldName = "field", fieldClass = FieldClass.class,
secondLineNumber = 47, secondFieldName = "field2", secondFieldClass = FieldClass.class)
secondLineNumber = 47, secondFieldName = "field2", secondFieldClass = FieldClass.class, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public void differentObjectsDifferentFields() {
FieldClass fc = new FieldClass();
FieldClass fc2 = new FieldClass();
Expand Down Expand Up @@ -76,7 +76,7 @@ public static void paramMayBeField(
@MayAlias(reason = "may alias with parameter and field",
lineNumber = 110, methodName = "main", fieldName = "field", fieldClass = FieldClass.class)
@NoAlias(reason = "no alias with parameter and field",
lineNumber = 111, methodName = "main", fieldName = "field2", fieldClass = FieldClass.class)
lineNumber = 111, methodName = "main", fieldName = "field2", fieldClass = FieldClass.class, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
Object o) {
}

Expand All @@ -85,15 +85,15 @@ public static void paramMayBeField(
secondLineNumber = 111, secondMethodName = "main", secondFieldName = "field", secondFieldClass = FieldClass.class)
@NoAlias(reason = "no alias of field via parameter",
lineNumber = 110, methodName = "main", fieldName = "field", fieldClass = FieldClass.class,
secondLineNumber = 111, secondMethodName = "main", secondFieldName = "field2", secondFieldClass = FieldClass.class)
secondLineNumber = 111, secondMethodName = "main", secondFieldName = "field2", secondFieldClass = FieldClass.class, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public static void fieldAliasViaParameter(FieldClass fc) {
fc.field.hashCode();
fc.field2.hashCode();
}

@NoAlias(reason = "no alias of field via parameter",
lineNumber = 110,methodName = "main", fieldName = "field", fieldClass = FieldClass.class,
secondLineNumber = 111, secondMethodName = "main", secondFieldName = "field2", secondFieldClass = FieldClass.class)
secondLineNumber = 111, secondMethodName = "main", secondFieldName = "field2", secondFieldClass = FieldClass.class, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public static void noFieldAliasViaParameter(FieldClass fc) {
fc.field.hashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.NoAlias;


import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.TypePointsToBasedAliasAnalysis;

public class NullAlias {

Expand All @@ -15,7 +15,7 @@ public static void main(String[] args) {
}

public static void paramIsAlwaysNull(
@NoAlias(reason = "parameter is always null", lineNumber = 20)
@NoAlias(reason = "parameter is always null", lineNumber = 20, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, TypePointsToBasedAliasAnalysis.class})
Object o) {
o.hashCode();
}
Expand All @@ -26,7 +26,7 @@ public static void paramMayBeNull(
o.hashCode();
}

@NoAlias(reason = "uVar is always null", lineNumber = 32, secondLineNumber = 32)
@NoAlias(reason = "uVar is always null", lineNumber = 32, secondLineNumber = 32, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, TypePointsToBasedAliasAnalysis.class})
public static void UVarIsAlwaysNull() {
Object o = null;
o.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.NoAlias;

import org.opalj.tac.fpcf.analyses.alias.AllocationSiteBasedAliasAnalysis;

public class ParameterAlias {

Expand Down Expand Up @@ -35,13 +35,13 @@ public static void main(String[] args) {
pa2.noAliasThisParamTwoMethods2();
}

public static void noAliasWithLocal(@NoAlias(reason = "noAlias with uVar", lineNumber = 40) Object o1) {
public static void noAliasWithLocal(@NoAlias(reason = "noAlias with uVar", lineNumber = 40, analyses = AllocationSiteBasedAliasAnalysis.class) Object o1) {
Object o2 = new Object();
o2.hashCode();
}

public static void noAliasWithParam(@NoAlias(reason = "noAlias with other parameter", id = 0) Object o1,
@NoAlias(reason = "noAlias with other parameter", id = 0) Object o2) {}
public static void noAliasWithParam(@NoAlias(reason = "noAlias with other parameter", id = 0, analyses = AllocationSiteBasedAliasAnalysis.class) Object o1,
@NoAlias(reason = "noAlias with other parameter", id = 0, analyses = AllocationSiteBasedAliasAnalysis.class) Object o2) {}

public static void mayAliasWithLocal(@MayAlias(reason = "mayAlias with uVar", lineNumber = 53) Object o1) {
Object o2 = new Object();
Expand All @@ -64,7 +64,8 @@ public static void mayAliasWithParam2(@MayAlias(reason = "mayAlias with other pa
public void mayAliasThisParam() {}

@NoAlias(reason = "no alias with this parameter and invoked uVar", thisParameter = true,
lineNumber = 28, methodName = "main")
lineNumber = 28, methodName = "main",
analyses = AllocationSiteBasedAliasAnalysis.class)
public void noAliasThisParam() {}

@MayAlias(reason = "may alias with this parameter of two methods", thisParameter = true, id = 3)
Expand All @@ -73,10 +74,12 @@ public void mayAliasThisParamTwoMethods1() {}
@MayAlias(reason = "may alias with this parameter of two methods", thisParameter = true, id = 3)
public void mayAliasThisParamTwoMethods2() {}

@NoAlias(reason = "no alias with this parameter of two methods", thisParameter = true, id = 4)
@NoAlias(reason = "no alias with this parameter of two methods", thisParameter = true, id = 4,
analyses = AllocationSiteBasedAliasAnalysis.class)
public void noAliasThisParamTwoMethods1() {}

@NoAlias(reason = "no alias with this parameter of two methods", thisParameter = true, id = 4)
@NoAlias(reason = "no alias with this parameter of two methods", thisParameter = true, id = 4,
analyses = AllocationSiteBasedAliasAnalysis.class)
public void noAliasThisParamTwoMethods2() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.NoAlias;


import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.TypePointsToBasedAliasAnalysis;

public class ReturnValueAlias {

@NoAlias(reason = "no Alias with local variable", lineNumber = 15)
@NoAlias(reason = "no Alias with local variable", lineNumber = 15, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public static Object noAliasWithLocal() {
Object o1 = new Object();

Expand Down Expand Up @@ -40,9 +40,9 @@ public static Object mayAliasWithLocal2() {
return o1;
}

@NoAlias(reason = "noAlias with parameter", id = 0)
@NoAlias(reason = "noAlias with parameter", id = 0, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, TypePointsToBasedAliasAnalysis.class})
public static Object noAliasWithParam(
@NoAlias(reason = "noAlias with parameter", id = 0)
@NoAlias(reason = "noAlias with parameter", id = 0, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, TypePointsToBasedAliasAnalysis.class})
Object a) {
Object o1 = new Object();
return o1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.NoAlias;

import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;

public class StaticFieldAlias {

@MayAlias(reason = "may alias with field and assigned uVar", lineNumber = 41, methodName = "reassignField")
@NoAlias(reason = "no alias with field and parameter", id = 1)
@NoAlias(reason = "no alias with field and return value", id = 3)
@NoAlias(reason = "no alias with field and unrelated uVar", lineNumber = 54, methodName = "noAlias")
@NoAlias(reason = "no alias with field and parameter", id = 1, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
@NoAlias(reason = "no alias with field and return value", id = 3, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
@NoAlias(reason = "no alias with field and unrelated uVar", lineNumber = 54, methodName = "noAlias", analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
@MayAlias(reason = "may alias with field and return value", id = 2)
@MayAlias(reason = "may alias with field and returned uVar", lineNumber = 65, methodName = "returnMayAliasField")
@MayAlias(reason = "may alias with field and return value via parameter", id = 5)
Expand Down Expand Up @@ -41,9 +41,9 @@ public static void reassignField() {
mayAliasField = o;
}

@NoAlias(reason = "no alias with field and return value", id = 3)
@NoAlias(reason = "no alias with field and return value", id = 3, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
public static Object noAlias(
@NoAlias(reason = "no alias with field and parameter", id = 1)
@NoAlias(reason = "no alias with field and parameter", id = 1, analyses = {AllocationSitePointsToBasedAliasAnalysis.class})
Object a) {
Object o = new Object();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import org.opalj.fpcf.properties.alias.MayAlias;
import org.opalj.fpcf.properties.alias.MustAlias;
import org.opalj.fpcf.properties.alias.NoAlias;

import org.opalj.tac.fpcf.analyses.alias.IntraProceduralAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;

public class UVarAlias {

@MustAlias(reason = "same local variable with single defSite without loop used",
lineNumber = 18,
secondLineNumber = 18)
secondLineNumber = 18, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, IntraProceduralAliasAnalysis.class})
public static void mustAliasLocals() {
Object o1 = new Object();

Expand All @@ -29,7 +30,7 @@ public static void mayAliasLoop() {

@MustAlias(reason = "same local variable with single defSite with loop in front of defSite",
lineNumber = 41,
secondLineNumber = 41)
secondLineNumber = 41, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, IntraProceduralAliasAnalysis.class})
public static void mustAliasLoopInFront() {
for (int i = 0; i < 10; i++) {
Object o1 = new Object();
Expand All @@ -42,7 +43,7 @@ public static void mustAliasLoopInFront() {

@MustAlias(reason = "same local variable with single defSite with loop behind defSite",
lineNumber = 50,
secondLineNumber = 50)
secondLineNumber = 50, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, IntraProceduralAliasAnalysis.class})
public static void mustAliasLoopBehind() {
Object o1 = new Object();

Expand All @@ -55,7 +56,7 @@ public static void mustAliasLoopBehind() {

@MustAlias(reason = "same local variable with single defSite with loop behind defSite",
lineNumber = 64,
secondLineNumber = 64)
secondLineNumber = 64, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, IntraProceduralAliasAnalysis.class})
public static void mustAliasLoopBehind2() {
Object o1 = new Object();

Expand All @@ -75,7 +76,7 @@ public static void mayAliasRecursion(Object a) {

@MustAlias(reason = "same local variable with single defSite with irrelevant recursion",
lineNumber = 82,
secondLineNumber = 83, secondParameterIndex = 0)
secondLineNumber = 83, secondParameterIndex = 0, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, IntraProceduralAliasAnalysis.class})
public static void mustAliasRecursion(Object a) {
a = new Object();
a.hashCode();
Expand Down Expand Up @@ -108,7 +109,7 @@ public static Object createNewObject() {

@NoAlias(reason = "no alias with local variables",
lineNumber = 116,
secondLineNumber = 117)
secondLineNumber = 117, analyses = {AllocationSitePointsToBasedAliasAnalysis.class, IntraProceduralAliasAnalysis.class})
public static void noAliasLocals() {
Object o1 = new Object();
Object o2 = new Object();
Expand All @@ -130,4 +131,42 @@ public static void mayAliasLocals() {
o1.hashCode();
o2.hashCode();
}

@MayAlias(reason = "same local variable with single defSite inside inner nested loop",
lineNumber = 142,
secondLineNumber = 142)
public static void mayAliasInnerNestedLoop() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Object o1 = new Object();
o1.hashCode();
}
}
}

@MayAlias(reason = "same local variable with single defSite inside outer nested loop",
lineNumber = 156,
secondLineNumber = 156)
public static void mayAliasOuterNestedLoop1() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Object o2 = new Object();
}
Object o1 = new Object();
o1.hashCode();
}
}

@MayAlias(reason = "same local variable with single defSite inside outer nested loop",
lineNumber = 166,
secondLineNumber = 166)
public static void mayAliasOuterNestedLoop2() {
for (int i = 0; i < 10; i++) {
Object o1 = new Object();
o1.hashCode();
for (int j = 0; j < 10; j++) {
Object o2 = new Object();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import org.opalj.br.fpcf.FPCFAnalysis;
import org.opalj.fpcf.properties.PropertyValidator;
import org.opalj.tac.fpcf.analyses.alias.IntraProceduralAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.TypePointsToBasedAliasAnalysis;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
Expand Down Expand Up @@ -109,6 +112,9 @@
/**
* All analyses that should be able to correctly detect this relation.
*/
Class<? extends FPCFAnalysis>[] analyses() default {};

Class<? extends FPCFAnalysis>[] analyses() default {
AllocationSitePointsToBasedAliasAnalysis.class,
TypePointsToBasedAliasAnalysis.class,
IntraProceduralAliasAnalysis.class
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import org.opalj.br.fpcf.FPCFAnalysis;
import org.opalj.fpcf.properties.PropertyValidator;
import org.opalj.tac.fpcf.analyses.alias.IntraProceduralAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.TypePointsToBasedAliasAnalysis;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
Expand Down Expand Up @@ -108,5 +111,9 @@
/**
* All analyses that should be able to correctly detect this relation.
*/
Class<? extends FPCFAnalysis>[] analyses() default {};
Class<? extends FPCFAnalysis>[] analyses() default {
AllocationSitePointsToBasedAliasAnalysis.class,
TypePointsToBasedAliasAnalysis.class,
IntraProceduralAliasAnalysis.class
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import org.opalj.br.fpcf.FPCFAnalysis;
import org.opalj.fpcf.properties.PropertyValidator;
import org.opalj.tac.fpcf.analyses.alias.IntraProceduralAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.AllocationSitePointsToBasedAliasAnalysis;
import org.opalj.tac.fpcf.analyses.alias.pointsto.TypePointsToBasedAliasAnalysis;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
Expand Down Expand Up @@ -108,5 +111,9 @@
/**
* All analyses that should be able to correctly detect this relation.
*/
Class<? extends FPCFAnalysis>[] analyses() default {};
Class<? extends FPCFAnalysis>[] analyses() default {
AllocationSitePointsToBasedAliasAnalysis.class,
TypePointsToBasedAliasAnalysis.class,
IntraProceduralAliasAnalysis.class
};
}
Loading
Loading