qilin.pta.tools.ZipperPTA Maven / Gradle / Ivy
/* Qilin - a Java Pointer Analysis Framework
* Copyright (C) 2021-2030 Qilin developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3.0 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
*/
package qilin.pta.tools;
import java.util.HashSet;
import java.util.Set;
import qilin.core.PTAScene;
import qilin.core.pag.*;
import qilin.parm.ctxcons.CtxConstructor;
import qilin.parm.heapabst.AllocSiteAbstractor;
import qilin.parm.heapabst.HeuristicAbstractor;
import qilin.parm.select.CtxSelector;
import qilin.parm.select.HeuristicSelector;
import qilin.parm.select.PartialMethodLvSelector;
import qilin.parm.select.PipelineSelector;
import qilin.pta.PTAConfig;
import qilin.pta.toolkits.zipper.Main;
import qilin.util.PTAUtils;
import qilin.util.Stopwatch;
import qilin.util.queue.QueueReader;
import sootup.core.jimple.basic.Local;
import sootup.core.jimple.basic.Value;
import sootup.core.jimple.common.constant.NullConstant;
import sootup.core.jimple.common.expr.AbstractInstanceInvokeExpr;
import sootup.core.jimple.common.expr.AbstractInvokeExpr;
import sootup.core.jimple.common.stmt.JAssignStmt;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.SootMethod;
import sootup.core.types.ReferenceType;
/*
* refer to "Precision-Guided Context Sensitivity for Pointer Analysis" (OOPSLA'18)
* and "A Principled Approach to Selective Context Sensitivity for Pointer Analysis" (TOPLAS'20)
* */
public class ZipperPTA extends StagedPTA {
private final Set PCMs = new HashSet<>();
/*
* Zipper support object-sensitivity, callsite-sensitivity by using corresponding
* context-constructor.
* */
public ZipperPTA(PTAScene scene, int k, int hk, CtxConstructor ctxCons) {
super(scene);
this.ctxCons = ctxCons;
CtxSelector us = new PartialMethodLvSelector(k, hk, PCMs);
if (PTAConfig.v().getPtaConfig().enforceEmptyCtxForIgnoreTypes) {
this.ctxSel = new PipelineSelector(new HeuristicSelector(getView()), us);
} else {
this.ctxSel = us;
}
if (PTAConfig.v().getPtaConfig().mergeHeap) {
this.heapAbst = new HeuristicAbstractor(pag);
} else {
this.heapAbst = new AllocSiteAbstractor();
}
this.prePTA = new Spark(scene);
}
@Override
protected void preAnalysis() {
Stopwatch sparkTimer = Stopwatch.newAndStart("Spark");
prePTA.pureRun();
sparkTimer.stop();
System.out.println(sparkTimer);
Stopwatch zipperTimer = Stopwatch.newAndStart("Zipper");
Main.run(prePTA, PCMs);
zipperTimer.stop();
System.out.println(zipperTimer);
extraStats();
}
protected void extraStats() {
int[] RM = new int[1], PCN = new int[1], NPCN = new int[1];
int[] totalN = new int[1];
for (ContextMethod momc : prePTA.getReachableMethods()) {
SootMethod method = momc.method();
Set