public static LambdaSummaryClass findOrCreate(CGNode caller, SSAInvokeDynamicInstruction inst) { if (! summaries.containsKey(inst.getBootstrap())) { String bootstrapCls = caller.getMethod().getDeclaringClass().getName().toString().replace("/", "$").substring(1); int bootstrapIndex = inst.getBootstrap().getIndexInClassFile(); TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Lwala/lambda" + '$' + bootstrapCls + '$' + bootstrapIndex); LambdaSummaryClass cls = new LambdaSummaryClass(ref, caller.getClassHierarchy(), inst); caller.getClassHierarchy().addClass(cls); summaries.put(inst.getBootstrap(), cls); } return summaries.get(inst.getBootstrap()); }
public static LambdaSummaryClass findOrCreate(CGNode caller, SSAInvokeDynamicInstruction inst) { if (! summaries.containsKey(inst.getBootstrap())) { String bootstrapCls = caller.getMethod().getDeclaringClass().getName().toString().replace("/", "$").substring(1); int bootstrapIndex = inst.getBootstrap().getIndexInClassFile(); TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Lwala/lambda" + '$' + bootstrapCls + '$' + bootstrapIndex); LambdaSummaryClass cls = new LambdaSummaryClass(ref, caller.getClassHierarchy(), inst); caller.getClassHierarchy().addClass(cls); summaries.put(inst.getBootstrap(), cls); } return summaries.get(inst.getBootstrap()); }
/** * Add constraints to represent the flow of exceptions to the exceptional return value for this node */ protected void addNodePassthruExceptionConstraints(CGNode node, IR ir) { // add constraints relating to thrown exceptions that reach the exit // block. List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock()); PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node); IClass c = node.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable); addExceptionDefConstraints(ir, node, peis, exception, Collections.singleton(c)); }
/** * Add constraints to represent the flow of exceptions to the exceptional return value for this node */ protected void addNodePassthruExceptionConstraints(CGNode node, IR ir) { // add constraints relating to thrown exceptions that reach the exit block. List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock()); PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node); IClass c = node.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable); addExceptionDefConstraints(ir, node, peis, exception, Collections.singleton(c)); }
/** * Add constraints to represent the flow of exceptions to the exceptional return value for this node */ protected void addNodePassthruExceptionConstraints(CGNode node, IR ir) { // add constraints relating to thrown exceptions that reach the exit block. List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock()); PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node); IClass c = node.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable); addExceptionDefConstraints(ir, node, peis, exception, Collections.singleton(c)); }
/** * Add constraints to represent the flow of exceptions to the exceptional return value for this node */ protected void addNodePassthruExceptionConstraints(CGNode node, IR ir) { // add constraints relating to thrown exceptions that reach the exit // block. List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock()); PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node); IClass c = node.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable); addExceptionDefConstraints(ir, node, peis, exception, Collections.singleton(c)); }
/** * Add constraints to represent the flow of exceptions to the exceptional return value for this node */ protected void addNodePassthruExceptionConstraints(CGNode node, IRView ir, DefUse du) { // add constraints relating to thrown exceptions that reach the exit block. List<ProgramCounter> peis = getIncomingPEIs(ir, ir.getExitBlock()); PointerKey exception = getPointerKeyForExceptionalReturnValue(node); TypeReference throwableType = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().getThrowableType(); IClass c = node.getClassHierarchy().lookupClass(throwableType); addExceptionDefConstraints(ir, du, node, peis, exception, Collections.singleton(c)); }
/** * Add constraints to represent the flow of exceptions to the exceptional return value for this node */ protected void addNodePassthruExceptionConstraints(CGNode node, IRView ir, DefUse du) { // add constraints relating to thrown exceptions that reach the exit block. List<ProgramCounter> peis = getIncomingPEIs(ir, ir.getExitBlock()); PointerKey exception = getPointerKeyForExceptionalReturnValue(node); TypeReference throwableType = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().getThrowableType(); IClass c = node.getClassHierarchy().lookupClass(throwableType); addExceptionDefConstraints(ir, du, node, peis, exception, Collections.singleton(c)); }
final IClassHierarchy cha = node.getClassHierarchy(); final IR ir = node.getIR(); if (ir == null)
final IClassHierarchy cha = node.getClassHierarchy(); final IR ir = node.getIR(); if (ir == null)
private Set<CodeElement> getFieldAccessCodeElts(CGNode node, SSAFieldAccessInstruction inst) { if (inst.isStatic()) { return getStaticFieldAccessCodeElts(inst); } Set<CodeElement> elts = HashSetFactory.make(); final FieldReference fieldRef = inst.getDeclaredField(); final IField field = node.getClassHierarchy().resolveField(fieldRef); PointerKey pk = pa.getHeapModel().getPointerKeyForLocal(node, inst.getRef()); final OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(pk); if (pointsToSet.isEmpty()) { InstanceKey ik = new ConcreteTypeKey(field.getDeclaringClass()); elts.add(new FieldElement(ik, fieldRef)); elts.add(new InstanceKeyElement(ik)); } else { for (InstanceKey ik : pointsToSet) { elts.add(new FieldElement(ik, fieldRef)); elts.add(new InstanceKeyElement(ik)); } } return elts; }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }
@Override public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) { if (! site.getDeclaredTarget().getName().equals(MethodReference.clinitName) && caller.getClassHierarchy().lookupClass(TypeReference.LambdaMetaFactory) != null && caller.getClassHierarchy().lookupClass(TypeReference.LambdaMetaFactory).equals( caller.getClassHierarchy().lookupClass(site.getDeclaredTarget().getDeclaringClass()))) summaries.put(invoke.getBootstrap(), new SummarizedMethod(ref, summary, caller.getClassHierarchy().lookupClass(site.getDeclaredTarget().getDeclaringClass())));
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { IClass declaringClass = callee.getDeclaringClass(); IMethod method = declaringClass.getMethod(AstMethodReference.fnSelector); Context baseCtxt = base.getCalleeTarget(caller, site, callee, receiver); if (method != null) { TypeName tn = method.getReference().getDeclaringClass().getName(); if (tn.equals(APPLY_TYPE_NAME)) { boolean isNonNullArray = false; if (receiver.length >= 4) { InstanceKey argsList = receiver[3]; if (argsList != null && argsList.getConcreteType().equals(caller.getClassHierarchy().lookupClass(JavaScriptTypes.Array))) { isNonNullArray = true; } } if (USE_ONE_LEVEL && caller.getContext().get(APPLY_NON_NULL_ARGS) == null) baseCtxt = oneLevel.getCalleeTarget(caller, site, callee, receiver); return new ApplyContext(baseCtxt, isNonNullArray); } else if (USE_ONE_LEVEL && tn.equals(CALL_TYPE_NAME)) { return oneLevel.getCalleeTarget(caller, site, callee, receiver); } } return baseCtxt; }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { IClass declaringClass = callee.getDeclaringClass(); IMethod method = declaringClass.getMethod(AstMethodReference.fnSelector); Context baseCtxt = base.getCalleeTarget(caller, site, callee, receiver); if (method != null) { TypeName tn = method.getReference().getDeclaringClass().getName(); if (tn.equals(APPLY_TYPE_NAME)) { boolean isNonNullArray = false; if (receiver.length >= 4) { InstanceKey argsList = receiver[3]; if (argsList != null && argsList.getConcreteType().equals(caller.getClassHierarchy().lookupClass(JavaScriptTypes.Array))) { isNonNullArray = true; } } if (USE_ONE_LEVEL && caller.getContext().get(APPLY_NON_NULL_ARGS) == null) baseCtxt = oneLevel.getCalleeTarget(caller, site, callee, receiver); return new ApplyContext(baseCtxt, isNonNullArray); } else if (USE_ONE_LEVEL && tn.equals(CALL_TYPE_NAME)) { return oneLevel.getCalleeTarget(caller, site, callee, receiver); } } return baseCtxt; }
@Override protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) { // in JavaScript, the 'new' instruction is wrapped in a synthetic constructor method. we want the // caller of that constructor method, which we obtain from the context for the constructor method final Context creatorContext = smik.getCreator().getContext(); CGNode callerOfConstructor = (CGNode) creatorContext.get(ContextKey.CALLER); Collection<CGNode> result = null; if (callerOfConstructor != null) { return Collections.singleton(callerOfConstructor); } else { CallString cs = (CallString) creatorContext.get(CallStringContextSelector.CALL_STRING); if (cs != null) { IMethod[] methods = cs.getMethods(); assert methods.length == 1; IMethod m = methods[0]; result = builder.getCallGraph().getNodes(m.getReference()); } } if (result == null) { IClassHierarchy cha = smik.getCreator().getClassHierarchy(); MethodReference ref = MethodReference.findOrCreate(JavaScriptLoader.JS, TypeReference.findOrCreate(cha.getLoaders()[0].getReference(), name.snd), AstMethodReference.fnAtomStr, AstMethodReference.fnDesc.toString()); final IMethod method = cha.resolveMethod(ref); if (method != null) { return builder.getCallGraph().getNodes(method.getReference()); } } return result; }
@Override protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) { // in JavaScript, the 'new' instruction is wrapped in a synthetic constructor method. we want the // caller of that constructor method, which we obtain from the context for the constructor method final Context creatorContext = smik.getCreator().getContext(); CGNode callerOfConstructor = (CGNode) creatorContext.get(ContextKey.CALLER); Collection<CGNode> result = null; if (callerOfConstructor != null) { return Collections.singleton(callerOfConstructor); } else { CallString cs = (CallString) creatorContext.get(CallStringContextSelector.CALL_STRING); if (cs != null) { IMethod[] methods = cs.getMethods(); assert methods.length == 1; IMethod m = methods[0]; result = builder.getCallGraph().getNodes(m.getReference()); } } if (result == null) { IClassHierarchy cha = smik.getCreator().getClassHierarchy(); MethodReference ref = MethodReference.findOrCreate(JavaScriptLoader.JS, TypeReference.findOrCreate(cha.getLoaders()[0].getReference(), name.snd), AstMethodReference.fnAtomStr, AstMethodReference.fnDesc.toString()); final IMethod method = cha.resolveMethod(ref); if (method != null) { return builder.getCallGraph().getNodes(method.getReference()); } } return result; }
public static int countApplicationNormals(Collection<Statement> slice) { int count = 0; for (Statement s : slice) { if (s.getKind().equals(Statement.Kind.NORMAL)) { AnalysisScope scope = s.getNode().getClassHierarchy().getScope(); if (scope.isApplicationLoader(s.getNode().getMethod().getDeclaringClass().getClassLoader())) { count++; } } } return count; } public static int countConditionals(Collection<Statement> slice) {
public static int countApplicationAllocations(Collection<Statement> slice) { int count = 0; for (Statement s : slice) { if (s.getKind().equals(Statement.Kind.NORMAL)) { NormalStatement ns = (NormalStatement) s; if (ns.getInstruction() instanceof SSANewInstruction) { AnalysisScope scope = s.getNode().getClassHierarchy().getScope(); if (scope.isApplicationLoader(s.getNode().getMethod().getDeclaringClass().getClassLoader())) { count++; } } } } return count; }