Skip to content

Commit

Permalink
(1) refactor code (2) upgrade gradle to 7.4 (3) support gradle test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongjie committed Feb 16, 2022
1 parent bcf008e commit eb482ad
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 280 deletions.
19 changes: 13 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ plugins {

group 'qilin'
version '1.0-SNAPSHOT'
sourceCompatibility = 16

java {
toolchain {
languageVersion = JavaLanguageVersion.of(16)
}
}

repositories {
mavenCentral()
}

dependencies {
implementation(project(':qilin.microben'))
implementation(project(':qilin.pta'))
implementation(project(':qilin.core'))
implementation(project(':qilin.microben'))
implementation(project(':qilin.util'))
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
Expand Down Expand Up @@ -50,10 +55,6 @@ subprojects {
group rootProject.group
version rootProject.version

// sourceCompatibility = 11
sourceCompatibility = 16


task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allJava
Expand All @@ -64,6 +65,12 @@ subprojects {
from javadoc.destinationDir
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(16)
vendor = JvmVendorSpec.ADOPTIUM
}
}
publishing.publications {
qilin(MavenPublication) {
from components.java
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.installations.auto-download=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
10 changes: 8 additions & 2 deletions qilin.core/src/qilin/core/CorePTA.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class CorePTA extends PTA {
protected CtxSelector ctxSel;
protected HeapAbstractor heapAbst;

public CtxSelector getContextSelector() {
public CtxSelector ctxSelector() {
return ctxSel;
}

Expand All @@ -53,6 +53,11 @@ public HeapAbstractor heapAbstractor() {
return heapAbst;
}

public CtxConstructor ctxConstructor() {
return ctxCons;
}


public abstract Propagator getPropagator();

@Override
Expand Down Expand Up @@ -226,7 +231,8 @@ public PointsToSet reachingObjects(SootField f) {

public PointsToSet reachingObjectsInternal(PointsToSet s, final SparkField f) {
PointsToSetInternal bases = (PointsToSetInternal) s;
final PointsToSetInternal ret = setFactory.newSet((f instanceof SootField) ? ((SootField) f).getType() : null, pag);
final PointsToSetInternal ret = setFactory.newSet((f instanceof SootField) ? ((SootField) f).getType() : null,
pag);
for (ContextField contextField : pag.getContextFieldVarNodeMap().getOrDefault(f, Collections.emptyMap()).values()) {
AllocNode base = contextField.getBase();
if (bases.contains(base)) {
Expand Down
39 changes: 8 additions & 31 deletions qilin.core/src/qilin/core/PTA.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import qilin.core.solver.Propagator;
import qilin.parm.ctxcons.CtxConstructor;
import qilin.parm.heapabst.HeapAbstractor;
import qilin.parm.select.CtxSelector;
import qilin.stat.PTAEvaluator;
import qilin.util.PTAUtils;
import soot.Context;
Expand All @@ -53,13 +54,11 @@ public abstract class PTA implements PointsToAnalysis {
protected CallGraphBuilder cgb;
protected ExceptionHandler eh;
protected P2SetFactory setFactory;
protected PTAEvaluator evaluator;

public PTA() {
this.pag = createPAG();
this.cgb = createCallGraphBuilder();
this.eh = new ExceptionHandler(this);
this.evaluator = new PTAEvaluator(this);
AllocNode rootBase = new AllocNode(pag, "ROOT", RefType.v("java.lang.Object"), null);
this.rootNode = new ContextAllocNode(pag, rootBase, CtxConstructor.emptyContext);
P2SetFactory oldF = HybridPointsToSet.getFactory();
Expand All @@ -71,47 +70,22 @@ public PTA() {

protected abstract CallGraphBuilder createCallGraphBuilder();

public void run() {
pureRun();
}

public void pureRun() {
for (int i = 0; i < 5; i++) {
System.gc();
}
Date startProp = new Date();
getPropagator().propagate();
Date endProp = new Date();
reportTime("Points-to resolution:", startProp, endProp);
}

private void dumpStats() {
if (CoreConfig.v().getOutConfig().dumppts) {
PTAUtils.dumpPts(this, !CoreConfig.v().getOutConfig().dumplibpts);
}
if (CoreConfig.v().getOutConfig().dumpCallGraph)
PTAUtils.dumpSlicedCallGraph(getCallGraph(),
parameterize(PTAScene.v().getMethod("<java.lang.String: java.lang.String valueOf(java.lang.Object)>"), emptyContext()));
if (CoreConfig.v().getOutConfig().dumppag) {
PTAUtils.dumpPAG(pag, "final_pag");
PTAUtils.dumpMPAGs(this, "mpags");
PTAUtils.dumpNodeNames("nodeNames");
}
}

private static void reportTime(String desc, Date start, Date end) {
long time = end.getTime() - start.getTime();
logger.info("[PTA] " + desc + " in " + time / 1000 + "." + (time / 100) % 10 + " seconds.");
}

public void run() {
evaluator.begin();
pureRun();
evaluator.end();
dumpStats();
pag.dumpPagStructureSize();
}

public PTAEvaluator evaluator() {
return this.evaluator;
}

public PAG getPag() {
return pag;
}
Expand Down Expand Up @@ -165,4 +139,7 @@ public Collection<SootMethod> getNakedReachableMethods() {

public abstract HeapAbstractor heapAbstractor();

public abstract CtxConstructor ctxConstructor();

public abstract CtxSelector ctxSelector();
}
3 changes: 3 additions & 0 deletions qilin.core/src/qilin/core/builder/FakeMainFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ private void makeFakeMain() {
}
}
}
if (CoreConfig.v().getPtaConfig().singleentry) {
return;
}
Value sv = getNextLocal(RefType.v("java.lang.String"));
Value mainThread = getNew(RefType.v("java.lang.Thread"));
Value mainThreadGroup = getNew(RefType.v("java.lang.ThreadGroup"));
Expand Down
13 changes: 7 additions & 6 deletions qilin.core/src/qilin/core/builder/MethodNodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,29 +236,30 @@ final public void caseNewExpr(NewExpr ne) {
@Override
final public void caseNewMultiArrayExpr(NewMultiArrayExpr nmae) {
ArrayType type = (ArrayType) nmae.getType();
type = (ArrayType) type.getElementType();
int pos = 0;
AllocNode prevAn = pag.heapAbstractor().abstractHeap(new JNewArrayExpr(type, nmae.getSize(pos)), type, method);
AllocNode prevAn = pag.heapAbstractor().abstractHeap(new JNewArrayExpr(type, nmae.getSize(pos)), nmae.getType(), method);
VarNode prevVn = pag.makeLocalVarNode(prevAn.getNewExpr(), prevAn.getType(), method);
mpag.addInternalEdge(prevAn, prevVn); // new
setResult(prevAn);
while (true) {
Type t = type.getElementType();
if (!(t instanceof ArrayType)) {
break;
}
type = (ArrayType) t;
++pos;
Value sizeVal;
if (pos < nmae.getSizeCount()) {
sizeVal = nmae.getSize(pos);
} else {
sizeVal = IntConstant.v(1);
}
AllocNode an = pag.heapAbstractor().abstractHeap(new JNewArrayExpr(type, sizeVal), type, method);
AllocNode an = pag.heapAbstractor().abstractHeap(new JNewArrayExpr(t, sizeVal), type, method);
VarNode vn = pag.makeLocalVarNode(an.getNewExpr(), an.getType(), method);
mpag.addInternalEdge(an, vn); // new
mpag.addInternalEdge(vn, pag.makeFieldRefNode(prevVn, ArrayElement.v())); // store
prevVn = vn;
if (!(t instanceof ArrayType)) {
break;
}
type = (ArrayType) t;
}
}

Expand Down
8 changes: 4 additions & 4 deletions qilin.core/src/qilin/core/pag/PAG.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,31 +315,31 @@ protected <K, V> boolean addToMap(Map<K, Set<V>> m, K key, V value) {
return valueList.add(value);
}

public boolean addAllocEdge(AllocNode from, VarNode to) {
private boolean addAllocEdge(AllocNode from, VarNode to) {
if (addToMap(alloc, from, to)) {
addToMap(allocInv, to, from);
return true;
}
return false;
}

public boolean addSimpleEdge(ValNode from, ValNode to) {
private boolean addSimpleEdge(ValNode from, ValNode to) {
if (addToMap(simple, from, to)) {
addToMap(simpleInv, to, from);
return true;
}
return false;
}

public boolean addStoreEdge(VarNode from, FieldRefNode to) {
private boolean addStoreEdge(VarNode from, FieldRefNode to) {
if (addToMap(storeInv, to, from)) {
addToMap(store, from, to);
return true;
}
return false;
}

public boolean addLoadEdge(FieldRefNode from, VarNode to) {
private boolean addLoadEdge(FieldRefNode from, VarNode to) {
if (addToMap(load, from, to)) {
addToMap(loadInv, to, from);
return true;
Expand Down
9 changes: 9 additions & 0 deletions qilin.core/src/qilin/stat/IEvaluator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package qilin.stat;

public interface IEvaluator {
int GB = 1024 * 1024 * 1024;

void begin();

void end();
}
19 changes: 12 additions & 7 deletions qilin.core/src/qilin/stat/PTAEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
* target methods) - Number of pointers (local and global) - Total points to
* sets size (local and global) context insensitive (convert to alloc site)
*/
public class PTAEvaluator {

private static final int GB = 1024 * 1024 * 1024;
private final RuntimeStat runtimeStat;
private final Exporter exporter;
private final PTA pta;
public class PTAEvaluator implements IEvaluator {
protected final RuntimeStat runtimeStat;
protected final Exporter exporter;
protected final PTA pta;

public PTAEvaluator(PTA pta) {
this.pta = pta;
Expand All @@ -49,6 +47,7 @@ public PTAEvaluator(PTA pta) {
/**
* Note the start of a qilin.pta run.
*/
@Override
public void begin() {
Runtime runtime = Runtime.getRuntime();// Getting the runtime reference
// from system
Expand All @@ -62,9 +61,14 @@ public void begin() {
runtimeStat.begin();
}

protected PointsToStat createPointsToStat() {
return new PointsToStat(pta);
}

/**
* Note the end of a qilin.pta run.
*/
@Override
public void end() {
// done with processing
runtimeStat.end();
Expand All @@ -75,7 +79,7 @@ public void end() {
BenchmarkStat benchmarkStat = new BenchmarkStat(pta);
CallGraphStat callGraphStat = new CallGraphStat(pta);
TypeClientStat typeClientStat = new TypeClientStat(pta);
PointsToStat ptsStat = new PointsToStat(pta);
PointsToStat ptsStat = createPointsToStat();
YummyStat yummyStat = new YummyStat(pta);
runtimeStat.export(exporter);
// memory stats
Expand All @@ -101,6 +105,7 @@ public void end() {

}

@Override
public String toString() {
return exporter.report();
}
Expand Down
Loading

0 comments on commit eb482ad

Please sign in to comment.