/** * Create and compute intraprocedural exception analysis. (IR from * node.getIR() will be used.) */ public IntraproceduralExceptionAnalysis(CGNode node, ExceptionFilter<SSAInstruction> filter, ClassHierarchy cha, PointerAnalysis<InstanceKey> pointerAnalysis) { this(node.getIR(), filter, cha, pointerAnalysis, node); }
/** * Create and compute intraprocedural exception analysis. (IR from * node.getIR() will be used.) */ public IntraproceduralExceptionAnalysis(CGNode node, ExceptionFilter<SSAInstruction> filter, ClassHierarchy cha, PointerAnalysis<InstanceKey> pointerAnalysis) { this(node.getIR(), filter, cha, pointerAnalysis, node); }
private static JavaScriptInvoke getInvokeInstruction(CGNode caller, CallSiteReference site) { IR callerIR = caller.getIR(); SSAAbstractInvokeInstruction callInstrs[] = callerIR.getCalls(site); assert callInstrs.length == 1; return (JavaScriptInvoke) callInstrs[0]; }
private static boolean hasNullIR(CGNode node) { boolean ret = node.getMethod().isNative(); assert node.getIR() != null || ret; return ret; }
@Override protected ExceptionFilter<SSAInstruction> computeFilter(CGNode node) { ArrayOutOfBoundsAnalysis analysis = new ArrayOutOfBoundsAnalysis(node.getIR()); return new ArrayOutOfBoundFilter(analysis); }
@Override protected ExceptionFilter<SSAInstruction> computeFilter(CGNode node) { IntraproceduralNullPointerAnalysis analysis = new IntraproceduralNullPointerAnalysis(node.getIR()); return new NullPointerExceptionFilter(analysis); }
private static int getNumberOfArgsPassed(CGNode caller, CallSiteReference site) { IR callerIR = caller.getIR(); SSAAbstractInvokeInstruction callStmts[] = callerIR.getCalls(site); assert callStmts.length == 1; int nargs = callStmts[0].getNumberOfPositionalParameters(); return nargs; }
protected void warnAboutImpreciseCallGraph(CGNode caller, CallSiteReference site) { IntIterator indices = caller.getIR().getCallInstructionIndices(site).intIterator(); IMethod callerMethod = caller.getMethod(); Position pos = null; if(indices.hasNext() && callerMethod instanceof AstMethod) { pos = ((AstMethod)callerMethod).getSourcePosition(indices.next()); } System.err.println("Detected improbable call to Function.prototype.call " + (pos == null ? "in function " + caller : "at position " + pos) + "; this is likely caused by call graph imprecision."); }
protected void warnAboutImpreciseCallGraph(CGNode caller, CallSiteReference site) { IntIterator indices = caller.getIR().getCallInstructionIndices(site).intIterator(); IMethod callerMethod = caller.getMethod(); Position pos = null; if(indices.hasNext() && callerMethod instanceof AstMethod) { pos = ((AstMethod)callerMethod).getSourcePosition(indices.next()); } System.err.println("Detected improbable call to Function.prototype.call " + (pos == null ? "in function " + caller : "at position " + pos) + "; this is likely caused by call graph imprecision."); }
@Override public boolean hasNormalEdge(ISSABasicBlock src, ISSABasicBlock dst) { boolean originalEdge = node.getIR().getControlFlowGraph().getNormalSuccessors(src).contains(dst); boolean result = originalEdge; SSAInstruction instruction = IntraproceduralExceptionAnalysis.getThrowingInstruction(src); if (instruction != null) { if (analysis.getFilter().getFilter(node).alwaysThrowsException(instruction)) { result = false; } } return result; }
@Override public boolean hasNoInterestingUses(CGNode node, int vn, DefUse du) { if (node.getMethod() instanceof AstMethod) { // uses in nested functions are interesting IntSet uses = ((AstIRFactory.AstIR) node.getIR()).lexicalInfo().getAllExposedUses(); if (uses.contains(vn)) { return false; } } return super.hasNoInterestingUses(node, vn, du); }
@Override public boolean hasNoInterestingUses(CGNode node, int vn, DefUse du) { if (node.getMethod() instanceof AstMethod) { // uses in nested functions are interesting IntSet uses = ((AstIRFactory.AstIR) node.getIR()).lexicalInfo().getAllExposedUses(); if (uses.contains(vn)) { return false; } } return super.hasNoInterestingUses(node, vn, du); }
@Override public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) { if (caller.getIR().getCalls(site)[0].getNumberOfUses() > index) { return IntSetUtil.make(new int[]{index}).union(base.getRelevantParameters(caller, site)); } else { return base.getRelevantParameters(caller, site); } }
@Override public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) { if (site.getDeclaredTarget().equals(JavaScriptMethods.ctorReference)) { IR callerIR = caller.getIR(); SSAAbstractInvokeInstruction callStmts[] = callerIR.getCalls(site); assert callStmts.length == 1; int nargs = callStmts[0].getNumberOfPositionalParameters(); return constructors.findOrCreateConstructorMethod(callerIR, callStmts[0], receiver, nargs - 1); } else { return base.getCalleeTarget(caller, site, receiver); } }
@Override public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) { // 0 for function (synthetic apply), 1 for this (function being invoked), 2 // for this arg of function being invoked, // 3 for arguments array MutableIntSet params = IntSetUtil.make(); for(int i = 0; i < 4 && i < caller.getIR().getCalls(site)[0].getNumberOfUses(); i++) { params.add(i); } return params.union(base.getRelevantParameters(caller, site)); }
@Override public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) { if (caller.getIR().getCalls(site)[0].getNumberOfUses() > index) { return IntSetUtil.make(new int[]{index}).union(base.getRelevantParameters(caller, site)); } else { return base.getRelevantParameters(caller, site); } }
private static IR getIR(CallGraph cg, String fullyQualifiedTypeName, String methodName, String methodParameter, String methodReturnType) { IClassHierarchy classHierarchy = cg.getClassHierarchy(); MethodReference methodRef = IRTests .descriptorToMethodRef( String.format("Source#%s#%s#(%s)%s", fullyQualifiedTypeName, methodName, methodParameter, methodReturnType), classHierarchy); IMethod method = classHierarchy.resolveMethod(methodRef); CGNode node = cg.getNode(method, Everywhere.EVERYWHERE); return node.getIR(); }
public static Statement findFirstAllocation(CGNode n) { IR ir = n.getIR(); for (int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction s = ir.getInstructions()[i]; if (s instanceof SSANewInstruction) { return new NormalStatement(n, i); } } Assertions.UNREACHABLE("failed to find allocation in " + n); return null; }
@Override public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) { MutableIntSet s = IntSetUtil.make(); for(int i = 0; i < caller.getIR().getCalls(site)[0].getNumberOfUses(); i++) { if (!caller.getMethod().getDeclaringClass().getClassLoader().getLanguage().methodsHaveDeclaredParameterTypes() || dispatchIndex(site, i)) { s.add(i); } } return s; }
@Test public void testArrayLiteral1() throws IllegalArgumentException, CancelException, IOException { runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), Collections.singletonList( cg -> { MethodReference mref = descriptorToMethodRef("Source#ArrayLiteral1#main#([Ljava/lang/String;)V", cg.getClassHierarchy()); CGNode node = cg.getNodes(mref).iterator().next(); SSAInstruction s = node.getIR().getInstructions()[2]; Assert.assertTrue("Did not find new array instruction.", s instanceof SSANewInstruction); Assert.assertTrue("", ((SSANewInstruction) s).getNewSite().getDeclaredType().isArrayType()); }), true, null); }