public static SSAInstruction getSSAInstruction(CallGraph cg, String methodSignature, int iindex) { SSACFG cfg = getSSACFG(methodSignature, cg); if (cfg == null) { logger.warn("getSSAInstruction:: Did not find SSACFG for " + methodSignature); } else { BasicBlock block = cfg.getBlockForInstruction(iindex); if (block != null) { for (Iterator<SSAInstruction> it = block.iterateNormalInstructions(); it.hasNext();) { SSAInstruction ins = it.next(); if (ins.iindex == iindex) { return ins; } } logger.warn("getSSAInstruction:: Did not find iindex " + iindex + " in SSACFG (" + methodSignature + ")"); } else logger.warn("getSSAInstruction:: Did not find basic block for iindex " + iindex + " in SSACFG (" + methodSignature + ")"); } return null; }
private boolean isBranchTaken(SSAPiInstruction pi, SSAConditionalBranchInstruction cnd) { final BasicBlock branchTargetBlock = this.ir.getControlFlowGraph() .getBlockForInstruction(cnd.getTarget()); return branchTargetBlock.getNumber() == pi.getSuccessor(); }
private boolean isBranchTaken(SSAPiInstruction pi, SSAConditionalBranchInstruction cnd) { final BasicBlock branchTargetBlock = this.ir.getControlFlowGraph() .getBlockForInstruction(cnd.getTarget()); return branchTargetBlock.getNumber() == pi.getSuccessor(); }
/** * @param site a call site in this method * @return the basic block corresponding to this instruction * @throws IllegalArgumentException if site is null */ @Override public ISSABasicBlock[] getBasicBlocksForCall(final CallSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } final IntSet s = callSiteMapping.getRelated(site.getProgramCounter()); if (s == null) { throw new IllegalArgumentException("invalid site: " + site); } final ISSABasicBlock[] result = new ISSABasicBlock[s.size()]; int index = 0; for (final IntIterator it = s.intIterator(); it.hasNext();) { final int i = it.next(); result[index++] = getControlFlowGraph().getBlockForInstruction(i); } return result; }
/** * @param site a call site in this method * @return the basic block corresponding to this instruction * @throws IllegalArgumentException if site is null */ @Override public ISSABasicBlock[] getBasicBlocksForCall(final CallSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } final IntSet s = callSiteMapping.getRelated(site.getProgramCounter()); if (s == null) { throw new IllegalArgumentException("invalid site: " + site); } final ISSABasicBlock[] result = new ISSABasicBlock[s.size()]; int index = 0; for (final IntIterator it = s.intIterator(); it.hasNext();) { final int i = it.next(); result[index++] = getControlFlowGraph().getBlockForInstruction(i); } return result; }
private void reuseOrCreatePi(SSAInstruction piCause, int ref) { int n = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(n); BasicBlock path = getCurrentSuccessor(); int outNum = shrikeCFG.getNumber(path); SSAPiInstruction pi = bb.getPiForRefAndPath(ref, path); if (pi == null) { pi = insts.PiInstruction(SSAInstruction.NO_INDEX, symbolTable.newSymbol(), ref, bb.getNumber(), outNum, piCause); bb.addPiForRefAndPath(ref, path, pi); } workingState.replaceValue(ref, pi.getDef()); }
private void reuseOrCreatePi(SSAInstruction piCause, int ref) { int n = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(n); BasicBlock path = getCurrentSuccessor(); int outNum = dexCFG.getNumber(path); SSAPiInstruction pi = bb.getPiForRefAndPath(ref, path); if (pi == null) { pi = insts.PiInstruction(getCurrentInstructionIndex(), symbolTable.newSymbol(), ref, bb.getNumber(), outNum, piCause); bb.addPiForRefAndPath(ref, path, pi); } workingState.replaceValue(ref, pi.getDef()); }
private void reuseOrCreatePi(SSAInstruction piCause, int ref) { int n = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(n); BasicBlock path = getCurrentSuccessor(); int outNum = shrikeCFG.getNumber(path); SSAPiInstruction pi = bb.getPiForRefAndPath(ref, path); if (pi == null) { pi = insts.PiInstruction(SSAInstruction.NO_INDEX, symbolTable.newSymbol(), ref, bb.getNumber(), outNum, piCause); bb.addPiForRefAndPath(ref, path, pi); } workingState.replaceValue(ref, pi.getDef()); }
private void recordExceptionTypes(Set<ExceptionHandler> set, IClassLoader loader) { for (ExceptionHandler handler : set) { TypeReference t = null; if (handler.getCatchClass() == null) { // by convention, in ShrikeCT this means catch everything t = TypeReference.JavaLangThrowable; } else if (handler.getCatchClassLoader() instanceof ClassLoaderReference) { t = ShrikeUtil.makeTypeReference((ClassLoaderReference)handler.getCatchClassLoader(), handler.getCatchClass()); } else { TypeReference exceptionType = ShrikeUtil.makeTypeReference(loader.getReference(), handler.getCatchClass()); IClass klass = null; klass = loader.lookupClass(exceptionType.getName()); if (klass == null) { Warnings.add(ExceptionLoadFailure.create(exceptionType, method)); t = exceptionType; } else { t = klass.getReference(); } } int instructionIndex = handler.getHandler(); IBasicBlock b = getBlockForInstruction(instructionIndex); if (!(b instanceof ExceptionHandlerBasicBlock)) { assert b instanceof ExceptionHandlerBasicBlock : "not exception handler " + b + " index " + instructionIndex; } ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) getBlockForInstruction(instructionIndex); bb.addCaughtExceptionType(t); } }
private void reuseOrCreatePi(SSAInstruction piCause, int ref) { int n = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(n); BasicBlock path = getCurrentSuccessor(); int outNum = dexCFG.getNumber(path); SSAPiInstruction pi = bb.getPiForRefAndPath(ref, path); if (pi == null) { pi = insts.PiInstruction(getCurrentInstructionIndex(), symbolTable.newSymbol(), ref, bb.getNumber(), outNum, piCause); bb.addPiForRefAndPath(ref, path, pi); } workingState.replaceValue(ref, pi.getDef()); }
private void recordExceptionTypes(Set<ExceptionHandler> set, IClassLoader loader) { for (ExceptionHandler handler : set) { TypeReference t = null; if (handler.getCatchClass() == null) { // by convention, in ShrikeCT this means catch everything t = TypeReference.JavaLangThrowable; } else if (handler.getCatchClassLoader() instanceof ClassLoaderReference) { t = ShrikeUtil.makeTypeReference((ClassLoaderReference)handler.getCatchClassLoader(), handler.getCatchClass()); } else { TypeReference exceptionType = ShrikeUtil.makeTypeReference(loader.getReference(), handler.getCatchClass()); IClass klass = null; klass = loader.lookupClass(exceptionType.getName()); if (klass == null) { Warnings.add(ExceptionLoadFailure.create(exceptionType, method)); t = exceptionType; } else { t = klass.getReference(); } } int instructionIndex = handler.getHandler(); IBasicBlock b = getBlockForInstruction(instructionIndex); if (!(b instanceof ExceptionHandlerBasicBlock)) { assert b instanceof ExceptionHandlerBasicBlock : "not exception handler " + b + " index " + instructionIndex; } ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) getBlockForInstruction(instructionIndex); bb.addCaughtExceptionType(t); } }
private int findRethrowException() { int index = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(index); if (bb.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) bb; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { // TODO: should we really use dominators here? maybe it would be cleaner to propagate // the notion of 'current exception to rethrow' using the abstract interpreter. if (dom == null) { dom = Dominators.make(cfg, cfg.entry()); } ISSABasicBlock x = bb; while (x != null) { if (x.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) x; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { x = dom.getIdom(x); } } // assert false; return -1; } }
@Test public void testSync1() { MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync1()V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR ir = cache.getIR(m); System.out.println(ir); SSACFG controlFlowGraph = ir.getControlFlowGraph(); Assert.assertEquals(1, controlFlowGraph.getSuccNodeCount(controlFlowGraph.getBlockForInstruction(21))); }
private int findRethrowException() { int index = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(index); if (bb.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) bb; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { // TODO: should we really use dominators here? maybe it would be cleaner to propagate // the notion of 'current exception to rethrow' using the abstract interpreter. if (dom == null) { dom = Dominators.make(cfg, cfg.entry()); } ISSABasicBlock x = bb; while (x != null) { if (x.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) x; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { x = dom.getIdom(x); } } // assert false; return -1; } }
@SuppressWarnings("unused") private int findRethrowException() { int index = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(index); if (bb.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) bb; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { // TODO: should we really use dominators here? maybe it would be cleaner to propagate // the notion of 'current exception to rethrow' using the abstract interpreter. if (dom == null) { dom = Dominators.make(cfg, cfg.entry()); } ISSABasicBlock x = bb; while (x != null) { if (x.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) x; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { x = dom.getIdom(x); } } // assert false; return -1; } }
@SuppressWarnings("unused") private int findRethrowException() { int index = getCurrentInstructionIndex(); SSACFG.BasicBlock bb = cfg.getBlockForInstruction(index); if (bb.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) bb; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { // TODO: should we really use dominators here? maybe it would be cleaner to propagate // the notion of 'current exception to rethrow' using the abstract interpreter. if (dom == null) { dom = Dominators.make(cfg, cfg.entry()); } ISSABasicBlock x = bb; while (x != null) { if (x.isCatchBlock()) { SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) x; SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction(); return s.getDef(); } else { x = dom.getIdom(x); } } // assert false; return -1; } }
@Test public void testSync3() { MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync3()V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR ir = cache.getIR(m); SSACFG controlFlowGraph = ir.getControlFlowGraph(); Assert.assertEquals(1, controlFlowGraph.getSuccNodeCount(controlFlowGraph.getBlockForInstruction(33))); }
@Test public void testSync2() { MethodReference mr = StringStuff.makeMethodReference("cfg.MonitorTest.sync2()V"); IMethod m = cha.resolveMethod(mr); IAnalysisCacheView cache = makeAnalysisCache(); IR ir = cache.getIR(m); System.out.println(ir); SSACFG controlFlowGraph = ir.getControlFlowGraph(); IntSet succs = controlFlowGraph.getSuccNodeNumbers(controlFlowGraph.getBlockForInstruction(13)); Assert.assertEquals(2, succs.size()); Assert.assertTrue(succs.contains(6)); Assert.assertTrue(succs.contains(7)); }