make configurable whether we apply an optimized version of hasExceptions()
This commit is contained in:
parent
65b9e97ae5
commit
9b8b323812
|
@ -58,7 +58,12 @@ public final class NullPointerAnalysis {
|
|||
|
||||
public static ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock>
|
||||
createIntraproceduralExplodedCFGAnalysis(TypeReference[] ignoredExceptions, IR ir, ParameterState paramState, MethodState mState) {
|
||||
return new ExplodedCFGNullPointerAnalysis(ignoredExceptions, ir, paramState, mState);
|
||||
return new ExplodedCFGNullPointerAnalysis(ignoredExceptions, ir, paramState, mState, false);
|
||||
}
|
||||
|
||||
public static ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock>
|
||||
createIntraproceduralExplodedCFGAnalysis(TypeReference[] ignoredExceptions, IR ir, ParameterState paramState, MethodState mState, boolean optHasException) {
|
||||
return new ExplodedCFGNullPointerAnalysis(ignoredExceptions, ir, paramState, mState, optHasException);
|
||||
}
|
||||
|
||||
public static ExceptionPruningAnalysis<SSAInstruction, ISSABasicBlock>
|
||||
|
@ -86,10 +91,16 @@ public final class NullPointerAnalysis {
|
|||
computeInterprocAnalysis(final TypeReference[] ignoredExceptions, final CallGraph cg,
|
||||
final MethodState defaultExceptionMethodState, final IProgressMonitor progress)
|
||||
throws WalaException, UnsoundGraphException, CancelException {
|
||||
return computeInterprocAnalysis(ignoredExceptions, cg, defaultExceptionMethodState, progress, false);
|
||||
}
|
||||
|
||||
public static InterprocAnalysisResult<SSAInstruction, IExplodedBasicBlock>
|
||||
computeInterprocAnalysis(final TypeReference[] ignoredExceptions, final CallGraph cg,
|
||||
final MethodState defaultExceptionMethodState, final IProgressMonitor progress, boolean optHasExceptions)
|
||||
throws WalaException, UnsoundGraphException, CancelException {
|
||||
final InterprocNullPointerAnalysis inpa = InterprocNullPointerAnalysis.compute(ignoredExceptions, cg,
|
||||
defaultExceptionMethodState, progress);
|
||||
defaultExceptionMethodState, progress, optHasExceptions);
|
||||
|
||||
return inpa.getResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,20 +64,22 @@ public final class InterprocNullPointerAnalysis {
|
|||
private final TypeReference[] ignoredExceptions;
|
||||
private final MethodState defaultMethodState;
|
||||
private final Map<CGNode, IntraprocAnalysisState> states;
|
||||
private final boolean optHasExceptions;
|
||||
|
||||
public static InterprocNullPointerAnalysis compute(final TypeReference[] ignoredExceptions, final CallGraph cg,
|
||||
final MethodState defaultMethodState, final IProgressMonitor progress)
|
||||
final MethodState defaultMethodState, final IProgressMonitor progress, boolean optHasExceptions)
|
||||
throws WalaException, UnsoundGraphException, CancelException {
|
||||
final InterprocNullPointerAnalysis inpa = new InterprocNullPointerAnalysis(ignoredExceptions, defaultMethodState);
|
||||
final InterprocNullPointerAnalysis inpa = new InterprocNullPointerAnalysis(ignoredExceptions, defaultMethodState, optHasExceptions);
|
||||
inpa.run(cg, progress);
|
||||
|
||||
return inpa;
|
||||
}
|
||||
|
||||
private InterprocNullPointerAnalysis(final TypeReference[] ignoredExceptions, final MethodState defaultMethodState) {
|
||||
private InterprocNullPointerAnalysis(final TypeReference[] ignoredExceptions, final MethodState defaultMethodState, boolean optHasExceptions) {
|
||||
this.ignoredExceptions = ignoredExceptions;
|
||||
this.defaultMethodState = defaultMethodState;
|
||||
this.states = new HashMap<CGNode, IntraprocAnalysisState>();
|
||||
this.optHasExceptions = optHasExceptions;
|
||||
}
|
||||
|
||||
private void run(final CallGraph cg, final IProgressMonitor progress) throws WalaException, UnsoundGraphException, CancelException {
|
||||
|
@ -147,7 +149,7 @@ public final class InterprocNullPointerAnalysis {
|
|||
|
||||
// run intraprocedural part again with invoke exception info
|
||||
final ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intra2 =
|
||||
NullPointerAnalysis.createIntraproceduralExplodedCFGAnalysis(ignoredExceptions, ir, paramState, mState);
|
||||
NullPointerAnalysis.createIntraproceduralExplodedCFGAnalysis(ignoredExceptions, ir, paramState, mState, optHasExceptions);
|
||||
final int deletedEdges2 = intra2.compute(progress);
|
||||
final ControlFlowGraph<SSAInstruction, IExplodedBasicBlock> cfg2 = intra2.getCFG();
|
||||
final IntraprocAnalysisState singleState1 = states.get(startNode);
|
||||
|
@ -174,7 +176,7 @@ public final class InterprocNullPointerAnalysis {
|
|||
states.put(startNode, new IntraprocAnalysisState());
|
||||
} else {
|
||||
final ExceptionPruningAnalysis<SSAInstruction, IExplodedBasicBlock> intra =
|
||||
NullPointerAnalysis.createIntraproceduralExplodedCFGAnalysis(ignoredExceptions, ir, paramState, defaultMethodState);
|
||||
NullPointerAnalysis.createIntraproceduralExplodedCFGAnalysis(ignoredExceptions, ir, paramState, defaultMethodState, optHasExceptions);
|
||||
final int deletedEdges = intra.compute(progress);
|
||||
// Analyze the method with intraprocedural scope
|
||||
final ControlFlowGraph<SSAInstruction, IExplodedBasicBlock> cfg = intra.getCFG();
|
||||
|
|
|
@ -37,12 +37,14 @@ public class ExplodedCFGNullPointerAnalysis implements ExceptionPruningAnalysis<
|
|||
private final IR ir;
|
||||
private final ParameterState initialState;
|
||||
private final MethodState mState;
|
||||
private final boolean optHasExceptions;
|
||||
|
||||
public ExplodedCFGNullPointerAnalysis(TypeReference[] ignoredExceptions, IR ir, ParameterState paramState, MethodState mState) {
|
||||
public ExplodedCFGNullPointerAnalysis(TypeReference[] ignoredExceptions, IR ir, ParameterState paramState, MethodState mState, boolean optHasExceptions) {
|
||||
this.ignoredExceptions = (ignoredExceptions != null ? ignoredExceptions.clone() : null);
|
||||
this.ir = ir;
|
||||
this.initialState = (paramState == null ? ParameterState.createDefault(ir.getMethod()) : paramState);
|
||||
this.mState = (mState == null ? MethodState.DEFAULT : mState);
|
||||
this.optHasExceptions = optHasExceptions;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -85,7 +87,7 @@ public class ExplodedCFGNullPointerAnalysis implements ExceptionPruningAnalysis<
|
|||
for (IExplodedBasicBlock bb : cfg) {
|
||||
if (bb.getInstruction() == null) continue;
|
||||
List<IExplodedBasicBlock> succ = cfg.getExceptionalSuccessors(bb);
|
||||
if (succ != null && succ.contains(cfg.exit())) {
|
||||
if (succ != null && !succ.isEmpty() && (!optHasExceptions || succ.contains(cfg.exit()))) {
|
||||
hasException = true;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue