for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlockReader block = program.basicBlockAt(i); block.readAllInstructions(reader); for (PhiReader phi : block.readPhis()) { Set<Integer> inputs = phi.readIncomings().stream() .map(incoming -> incoming.getValue().getIndex())
if (block.getExceptionVariable() != null) { sb.append(" @").append(stringifier.getVariableLabel(block.getExceptionVariable().getIndex())) .append(" := exception\n"); for (PhiReader phi : block.readPhis()) { sb.append(prefix).append(" "); sb.append("@").append(stringifier.getVariableLabel(phi.getReceiver().getIndex())).append(" := phi "); .append(" from ").append("$").append(incoming.getSource().getIndex()); for (InstructionIterator iterator = block.iterateInstructions(); iterator.hasNext();) { iterator.next(); insnSb.setLength(0); for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { sb.append(prefix).append(" catch "); if (tryCatch.getExceptionType() != null) { InstructionStringifier.escapeStringLiteral(tryCatch.getExceptionType(), sb); sb.append(" goto $").append(tryCatch.getHandler().getIndex()); sb.append("\n");
public static List<TryCatchBlock> copyTryCatches(BasicBlockReader block, Program target) { List<TryCatchBlock> result = new ArrayList<>(); for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { TryCatchBlock tryCatchCopy = new TryCatchBlock(); tryCatchCopy.setExceptionType(tryCatch.getExceptionType()); tryCatchCopy.setHandler(target.basicBlockAt(tryCatch.getHandler().getIndex())); result.add(tryCatchCopy); } return result; }
private ExceptionConsumer createExceptionConsumer(MethodDependency methodDep, BasicBlockReader block) { List<? extends TryCatchBlockReader> tryCatchBlocks = block.readTryCatchBlocks(); ClassReader[] exceptions = new ClassReader[tryCatchBlocks.size()]; DependencyNode[] vars = new DependencyNode[tryCatchBlocks.size()]; for (int i = 0; i < tryCatchBlocks.size(); ++i) { TryCatchBlockReader tryCatch = tryCatchBlocks.get(i); if (tryCatch.getExceptionType() != null) { exceptions[i] = dependencyAnalyzer.getClassSource().get(tryCatch.getExceptionType()); } if (tryCatch.getHandler().getExceptionVariable() != null) { vars[i] = methodDep.getVariable(tryCatch.getHandler().getExceptionVariable().getIndex()); } } return new ExceptionConsumer(dependencyAnalyzer, exceptions, vars, methodDep); }
blockIndex = i == 0 ? startBlock : substitutor.blockOffset + i; BasicBlock targetBlock = program.basicBlockAt(blockIndex); for (PhiReader templatePhi : templateBlock.readPhis()) { Phi phi = new Phi(); for (IncomingReader templateIncoming : templatePhi.readIncomings()) { incoming.setSource(substitutor.block(templateIncoming.getSource())); phi.getIncomings().add(incoming); int sourceIndex = templateIncoming.getSource().getIndex(); outgoings.get(sourceIndex).add(incoming); outgoingVars.get(sourceIndex).add(templateIncoming.getValue()); blockIndex = i == 0 ? startBlock : substitutor.blockOffset + i; BasicBlock targetBlock = program.basicBlockAt(blockIndex); if (templateBlock.getExceptionVariable() != null) { targetBlock.setExceptionVariable(substitutor.var(templateBlock.getExceptionVariable())); for (TryCatchBlockReader templateTryCatch : templateBlock.readTryCatchBlocks()) { TryCatchBlock tryCatch = new TryCatchBlock(); tryCatch.setExceptionType(templateTryCatch.getExceptionType()); templateBlock.readAllInstructions(substitutor);
BasicBlockReader block = program.basicBlockAt(i); if (block.getExceptionVariable() != null) { types[block.getExceptionVariable().getIndex()] = new InferenceType(InferenceKind.OBJECT, 0); block.readAllInstructions(reader); for (PhiReader phi : block.readPhis()) { for (IncomingReader incoming : phi.readIncomings()) { builder.addEdge(incoming.getValue().getIndex(), phi.getReceiver().getIndex());
BasicBlockReader block = program.basicBlockAt(i); currentExceptionConsumer = createExceptionConsumer(dep, block); block.readAllInstructions(reader); for (PhiReader phi : block.readPhis()) { DependencyNode receiverNode = nodes[phi.getReceiver().getIndex()]; for (IncomingReader incoming : phi.readIncomings()) { for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { dependencyAnalyzer.linkClass(tryCatch.getExceptionType());
public void addLocationsOfProgram(ProgramReader program) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlockReader block = program.basicBlockAt(i); block.readAllInstructions(this); } }
public BasicBlock block(BasicBlockReader block) { if (block == null) { return null; } return program.basicBlockAt(blockOffset + block.getIndex()); }
for (PhiReader phi : block.readPhis()) { for (IncomingReader incoming : phi.readIncomings()) { outgoings.get(incoming.getSource().getIndex()).add(incoming); InstructionIterator iterator = currentBlock.iterateInstructions(); try { while (iterator.hasNext()) {
@Override protected void processMethod(MethodDependency methodDep) { MethodReader method = methodDep.getMethod(); ProgramReader program = method.getProgram(); if (program != null) { FastInstructionAnalyzer instructionAnalyzer = new FastInstructionAnalyzer(this); instructionAnalyzer.setCaller(method.getReference()); for (BasicBlockReader block : program.getBasicBlocks()) { block.readAllInstructions(instructionAnalyzer); for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { linkClass(tryCatch.getExceptionType()); } } } methodDep.variableNodes = new DependencyNode[program.variableCount()]; for (int i = 0; i < methodDep.variableNodes.length; ++i) { methodDep.variableNodes[i] = instancesNode; } } if (method.hasModifier(ElementModifier.SYNCHRONIZED)) { processAsyncMethod(methodDep); } }
public static List<Phi> copyPhis(BasicBlockReader block, Program target) { List<Phi> result = new ArrayList<>(); for (PhiReader phi : block.readPhis()) { Phi phiCopy = new Phi(); phiCopy.setReceiver(target.variableAt(phi.getReceiver().getIndex())); for (IncomingReader incoming : phi.readIncomings()) { Incoming incomingCopy = new Incoming(); incomingCopy.setSource(target.basicBlockAt(incoming.getSource().getIndex())); incomingCopy.setValue(target.variableAt(incoming.getValue().getIndex())); phiCopy.getIncomings().add(incomingCopy); } result.add(phiCopy); } return result; }
public static void copyBasicBlock(BasicBlockReader block, BasicBlock target) { Program targetProgram = target.getProgram(); if (block.getExceptionVariable() != null) { target.setExceptionVariable(targetProgram.variableAt(block.getExceptionVariable().getIndex())); } InstructionCopyReader copyReader = new InstructionCopyReader(targetProgram); for (InstructionIterator iterator = block.iterateInstructions(); iterator.hasNext();) { iterator.next(); iterator.read(copyReader); target.add(copyReader.getCopy()); } target.getPhis().addAll(copyPhis(block, targetProgram)); target.getTryCatchBlocks().addAll(copyTryCatches(block, targetProgram)); }
private boolean pickExceptionHandler(Throwable e) { for (TryCatchBlockReader tryCatch : currentBlock.readTryCatchBlocks()) { Class<?> exceptionType; try { exceptionType = tryCatch.getExceptionType() != null ? Class.forName(tryCatch.getExceptionType(), false, classLoader) : null; } catch (ClassNotFoundException cnfe) { throw new RuntimeException("Can't find exception class " + tryCatch.getExceptionType()); } if (exceptionType == null || exceptionType.isInstance(e)) { currentBlock = tryCatch.getProtectedBlock(); return true; } } return false; }
blockIndex = i == 0 ? startBlock : substitutor.blockOffset + i; BasicBlock targetBlock = program.basicBlockAt(blockIndex); for (PhiReader templatePhi : templateBlock.readPhis()) { Phi phi = new Phi(); for (IncomingReader templateIncoming : templatePhi.readIncomings()) { incoming.setSource(substitutor.block(templateIncoming.getSource())); phi.getIncomings().add(incoming); int sourceIndex = templateIncoming.getSource().getIndex(); outgoings.get(sourceIndex).add(incoming); outgoingVars.get(sourceIndex).add(templateIncoming.getValue()); blockIndex = i == 0 ? startBlock : substitutor.blockOffset + i; BasicBlock targetBlock = program.basicBlockAt(blockIndex); if (templateBlock.getExceptionVariable() != null) { targetBlock.setExceptionVariable(substitutor.var(templateBlock.getExceptionVariable())); for (TryCatchBlockReader templateTryCatch : templateBlock.readTryCatchBlocks()) { TryCatchBlock tryCatch = new TryCatchBlock(); tryCatch.setExceptionType(templateTryCatch.getExceptionType()); templateBlock.readAllInstructions(substitutor);
BasicBlockReader block = program.basicBlockAt(i); if (block.getExceptionVariable() != null) { types[block.getExceptionVariable().getIndex()] = VariableType.OBJECT; block.readAllInstructions(reader); for (PhiReader phi : block.readPhis()) { for (IncomingReader incoming : phi.readIncomings()) { builder.addEdge(incoming.getValue().getIndex(), phi.getReceiver().getIndex());
BasicBlockReader block = program.basicBlockAt(i); currentExceptionConsumer = createExceptionConsumer(dep, block); block.readAllInstructions(reader); for (PhiReader phi : block.readPhis()) { DependencyNode receiverNode = nodes[phi.getReceiver().getIndex()]; for (IncomingReader incoming : phi.readIncomings()) { for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { dependencyChecker.linkClass(tryCatch.getExceptionType(), new CallLocation(caller.getMethod()));
private boolean hasMonitor(MethodReader method) { if (method.hasModifier(ElementModifier.SYNCHRONIZED)) { return true; } ProgramReader program = method.getProgram(); AsyncInstructionReader insnReader = new AsyncInstructionReader(); for (int i = 0; i < program.basicBlockCount(); ++i) { program.basicBlockAt(i).readAllInstructions(insnReader); if (insnReader.async) { return true; } } return false; }
private BasicBlock copyBlock(BasicBlockReader block) { return programCopy.basicBlockAt(block.getIndex()); }
for (PhiReader phi : block.readPhis()) { for (IncomingReader incoming : phi.readIncomings()) { outgoings.get(incoming.getSource().getIndex()).add(incoming); InstructionIterator iterator = currentBlock.iterateInstructions(); try { while (iterator.hasNext()) {