Java Examples for com.ibm.wala.classLoader.CallSiteReference
The following java examples will help you to understand the usage of com.ibm.wala.classLoader.CallSiteReference. These source code samples are taken from different open source projects.
Example 1
Project: wala-mirror-master File: DexIMethod.java View source code |
//------------------------------------------- // MethodAnnotationIteratorDelegate Methods //------------------------------------------- // /** // * Delegate called by the class in order to parse the method annotations. // */ // public void processMethodAnnotations(MethodIdItem mIdItem, // AnnotationSetItem anoSet) { // //System.out.println("DexIMethod: processMethodAnnotations()"); // if ( mIdItem.equals(eMethod.method) ){ // AnnotationItem[] items = anoSet.getAnnotations(); // for (AnnotationItem item : items) { // logger.debug("ANNOTATION"+item.toString()); // } // // } // } /** * * @throws InvalidClassFileException * @throws UnsupportedOperationException * * @todo Review this implementation - it may be horribly wrong! */ @Override public Collection<CallSiteReference> getCallSites() throws InvalidClassFileException { Collection<CallSiteReference> empty = Collections.emptySet(); if (isNative()) { return empty; } // assert(false) : "Please review getCallSites-Implementation before use!"; // TODO ArrayList<CallSiteReference> csites = new ArrayList<CallSiteReference>(); // XXX The call Sites in this method or to this method?!!! for (Instruction inst : instructions()) { if (inst instanceof Invoke) { // Locate the Target MethodReference target = MethodReference.findOrCreate(// XXX: Is this the correct class loader? getDeclaringClass().getClassLoader().getReference(), ((Invoke) inst).clazzName, ((Invoke) inst).methodName, ((Invoke) inst).descriptor); csites.add(CallSiteReference.make(// programCounter inst.pc, // declaredTarget target, // invocationCode ((Invoke) inst).getInvocationCode())); logger.info("\tClass Name:\t" + ((Invoke) inst).clazzName); logger.info("\tMethod Name:\t" + ((Invoke) inst).methodName); logger.info("\tSignature:\t" + ((Invoke) inst).descriptor); } } return Collections.unmodifiableCollection(csites); }
Example 2
Project: keshmesh-master File: LCK02JBugDetector.java View source code |
/* * The method Object.getClass() has a normal allocation instruction. This * method look for the predecessors of the CGNode containing the normal * allocation instruction. These predecessors make calls to * Object.getClass(). This method iterates over all such invocations and * returns the type names of the receivers of all such method invocations. * This method is an attempt to make the analysis independent of receiver * instance context. But, we encountered several problems while using this * method on contexts lighter than the receiver instance context. For * example, cheaper contexts are less precise and thus report too many * predecessors for a the CGNode of Object.getClass(). And, too many * predecessors result in too many type names to be reported as potential * receivers of a call to getClass. Specifically, several exception classes * get reported as the type names of the receivers of the call to * Object.getClass. */ @Deprecated private void addSynchronizedClassTypeNames(Set<String> result, NormalAllocationInNode normalAllocationInNode) { { CGNode normalAllocationCGNode = normalAllocationInNode.getNode(); Iterator<CGNode> predNodesIterator = basicAnalysisData.callGraph.getPredNodes(normalAllocationCGNode); while (predNodesIterator.hasNext()) { CGNode predNode = predNodesIterator.next(); Iterator<CallSiteReference> possibleSitesIterator = basicAnalysisData.callGraph.getPossibleSites(predNode, normalAllocationCGNode); while (possibleSitesIterator.hasNext()) { CallSiteReference possibleSite = possibleSitesIterator.next(); SSAAbstractInvokeInstruction[] calls = predNode.getIR().getCalls(possibleSite); for (SSAAbstractInvokeInstruction invokeInstruction : calls) { int invocationReceiverValueNumber = invokeInstruction.getReceiver(); PointerKey pointerKeyForReceiver = getPointerForValueNumber(predNode, invocationReceiverValueNumber); OrdinalSet<InstanceKey> receiverObjects = basicAnalysisData.pointerAnalysis.getPointsToSet(pointerKeyForReceiver); for (InstanceKey receiverInstanceKey : receiverObjects) { result.add(getJavaClassName(receiverInstanceKey.getConcreteType().getName())); } } } } } }
Example 3
Project: XSched-master File: TaskStringContextSelector.java View source code |
//do something like: have a base context selector (probably a default one).
//ask the base selector for a context
//check for the task context of the caller and add the tasks up to some length n
//combine the task string and the base context into a single context
//pretty much, steal from the nCFAContextSelector and its superclass CallStringContextSelector
@Override
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey receiver) {
Context baseContext = base.getCalleeTarget(caller, site, callee, receiver);
IR ir = caller.getIR();
if (WalaConstants.isTaskMethod(site.getDeclaredTarget())) {
SSAAbstractInvokeInstruction[] invokes = ir.getCalls(site);
assert invokes.length == 1;
//0 is the "this" of the invoke, 1 is the "now" parameter (1st param)
int now = invokes[0].getUse(1);
SSAInstruction creationSite = caller.getDU().getDef(now);
TaskCreationSite tcs = new TaskCreationSite(caller.getMethod(), (SSANewInstruction) creationSite);
return new TaskContextPair(tcs, baseContext);
} else {
//normal call
TaskCreationSite tcs = (TaskCreationSite) caller.getContext().get(TASK_CREATION_SITE);
return new TaskContextPair(tcs, baseContext);
}
}
Example 4
Project: privmem-master File: ScjContextSelector.java View source code |
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] actualParameters) {
ScjContext calleeContext;
// Handles the first nodes that is called from the synthetic fakeRoot
if (!(caller.getContext() instanceof ScjContext)) {
return immortal;
}
calleeContext = (ScjContext) caller.getContext();
if (isSubclassOf(callee, this.AEHIClass) && isFuncName(callee, "handleAsyncEvent")) {
calleeContext = new ScjContext(calleeContext, callee.getDeclaringClass().getName().toString(), ScjScopeType.PM);
} else if (this.isImplemented(callee, this.safeletIClass) && isFuncName(callee, "initializeApplication")) {
calleeContext = this.immortal;
} else if (isSubclassOf(callee, this.ManagedMemoryIClass)) {
if (isFuncName(callee, "enterPrivateMemory")) {
calleeContext = new ScjContext(calleeContext, getUniquePMName(), ScjScopeType.PM);
} else if (isFuncName(callee, "executeInOuterArea")) {
System.out.println("executeInOuterArea");
calleeContext = new ScjContext(calleeContext.getOuterStack());
} else if (isFuncName(callee, "executeInAreaOf")) {
util.error("Not supported by the analysis");
} else if (isFuncName(callee, "getCurrentManagedMemory")) {
util.error("Not supported by new SCJ revisions");
}
} else if (isFuncName(callee, "startMission") && callee.getDeclaringClass().getName().toString().equals("Ljavax/safetycritical/JopSystem")) {
calleeContext = new ScjContext(calleeContext, caller.getMethod().getDeclaringClass().getName().toString(), ScjScopeType.MISSION);
} else if (isFuncName(callee, "getSequencer") && this.isImplemented(callee, this.safeletIClass)) {
calleeContext = this.immortal;
}
if (ScjMemoryScopeAnalysis.analyseWithoutJRE == true && isFuncName(callee, "initialize") && isSubclassOf(callee, this.missionIClass)) {
calleeContext = new ScjContext(calleeContext, caller.getMethod().getDeclaringClass().getName().toString(), ScjScopeType.MISSION);
}
this.scopeStacks.add(calleeContext.scopeStack);
this.updateClassScopeMapping(callee, calleeContext.scopeStack);
this.updateMethodScope(callee, calleeContext.scopeStack);
return calleeContext;
}
Example 5
Project: sx10-master File: X10toCAstTranslator.java View source code |
public CAstNode visit(ConstructorDecl cd, WalkContext mc) { // Needs to examine the initializers in the ClassContext // and glue that code into the right place relative to the // constructor method body ("wherever that may turn out to be"). List /* <FieldDecl|Initializer> */ inits = mc.getInitializers(); Block body = cd.body(); if (hasSuperCall(body)) { // Split at call to super: // super(); // field initializer code // remainder of ctor body CAstNode[] bodyNodes = new CAstNode[inits.size() + body.statements().size()]; int idx = 0; for (Iterator iter = body.statements().iterator(); iter.hasNext(); ) { Stmt s = (Stmt) iter.next(); bodyNodes[idx++] = walkNodes(s, mc); if (idx == 1) { Assertions.productionAssertion(isSpecialCallStmt(s, ConstructorCall.SUPER)); idx = insertInitializers(mc, bodyNodes, false, idx); } } return makeNode(mc, fFactory, body, CAstNode.BLOCK_STMT, bodyNodes); } else if (hasThisCall(body)) { return walkNodes(body, mc); } else { // add explicit call to default super() // RMF 4/17/2009- The following search for a superClass default ctor // won't work if we process Object in source. In particular, the // superClass might be null. In that case, simply omit the explicit // super() call. ClassType superClass = (ClassType) ((ObjectType) cd.constructorDef().asInstance().container()).superClass(); CAstNode[] bodyNodes; int idx = 0; int bodyInitsSize = inits.size() + body.statements().size(); if (superClass != null) { ProcedureInstance defaultSuperCtor = findDefaultCtor(superClass); CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(defaultSuperCtor), IInvokeInstruction.Dispatch.SPECIAL); CAstNode superCall = makeNode(mc, fFactory, cd, CAstNode.CALL, makeNode(mc, fFactory, cd, CAstNode.SUPER), fFactory.makeConstant(callSiteRef)); bodyNodes = new CAstNode[bodyInitsSize + 1]; bodyNodes[idx++] = superCall; } else { // no super class, so no super call bodyNodes = new CAstNode[bodyInitsSize]; } idx = insertInitializers(mc, bodyNodes, false, idx); for (Iterator iter = body.statements().iterator(); iter.hasNext(); idx++) { Stmt s = (Stmt) iter.next(); bodyNodes[idx] = walkNodes(s, mc); } return makeNode(mc, fFactory, body, CAstNode.BLOCK_STMT, bodyNodes); } }
Example 6
Project: MemSAT-master File: WalaInformationImpl.java View source code |
private Stack<CallSite> makeCalleeStack(Stack<CallSite> current, CallSiteReference site, CGNode node) {
//
// fix this!
//
// must copy because references to the stack are captured,
// so
// mutating rather than copying will break everything.
//
Stack<CallSite> calleeStack = new LinkedStack<CallSite>();
for (CallSite ref : current) {
calleeStack.push(ref);
}
calleeStack.push(new CallSite(site, node));
return calleeStack;
}