public BasicBlock currentBlock() { return program.basicBlockAt(blockIndex); }
public BasicBlock block(BasicBlockReader block) { if (block == null) { return null; } return program.basicBlockAt(blockOffset + block.getIndex()); }
private void putLiveInGCRoots(Program program, List<Map<Instruction, int[]>> updateInformation) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); Map<Instruction, int[]> updatesByIndex = updateInformation.get(i); Instruction[] callSiteLocations = updatesByIndex.keySet().toArray(new Instruction[0]); ObjectIntMap<Instruction> instructionIndexes = getInstructionIndexes(block); Arrays.sort(callSiteLocations, Comparator.comparing(instructionIndexes::get)); for (Instruction callSiteLocation : updatesByIndex.keySet()) { int[] updates = updatesByIndex.get(callSiteLocation); storeLiveIns(block, callSiteLocation, updates); } } }
private void propagateAlongExceptions(Program program) { for (int i = 0; i < exceptions.length; i += 2) { int variable = nodeMapping[packNodeAndDegree(exceptions[i], 0)]; if (!formerNodeChanged[variable] && !nodeChanged[variable]) { continue; } BasicBlock block = program.basicBlockAt(exceptions[i + 1]); for (IntCursor type : types[variable]) { String typeName = typeList.get(type.value); propagateException(typeName, block); } } }
@Override public boolean optimize(MethodOptimizationContext context, Program program) { for (int i = 0; i < program.basicBlockCount(); ++i) { optimize(program.basicBlockAt(i)); } return false; }
private List<BasicBlock> buildBasicBlocksSequence(BasicBlock first) { List<BasicBlock> result = new ArrayList<>(2); BasicBlock block = program.basicBlockAt(mappings[first.getIndex()]); while (previousPtr.get(block.getIndex()) != block.getIndex()) { result.add(block); block = program.basicBlockAt(previousPtr.get(block.getIndex())); } result.add(block); Collections.reverse(result); return result; }
public void transformProgram() { for (int i = 0; i < program.basicBlockCount(); ++i) { transformBasicBlock(program.basicBlockAt(i)); } }
public void transform(Program program) { for (int i = 0; i < program.basicBlockCount(); ++i) { transform(program.basicBlockAt(i)); } }
void add(Instruction insn) { insn.setLocation(forcedLocation != null ? forcedLocation : location); program.basicBlockAt(blockIndex).add(insn); }
private void addSynthesizedPhis() { for (int i = 0; i < program.basicBlockCount(); ++i) { for (Phi phi : synthesizedPhisByBlock.get(i)) { if (!usedPhis.get(phi.getReceiver().getIndex())) { continue; } if (!phi.getIncomings().isEmpty()) { program.basicBlockAt(i).getPhis().add(phi); synthesizedPhis.add(phi); } } } }
private Statement generateJumpStatement(SwitchStatement stmt, int target) { Statement body = generateJumpStatement(program.basicBlockAt(target)); if (body == null) { BreakStatement breakStmt = new BreakStatement(); breakStmt.setTarget(stmt); body = breakStmt; } return body; }
public static boolean[] findEscapingVariables(Program program) { boolean[] escaping = new boolean[program.variableCount()]; InstructionAnalyzer analyzer = new InstructionAnalyzer(escaping); for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); for (Instruction insn : block) { insn.acceptVisitor(analyzer); } } return escaping; }
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 void fillExceptionHandlers(Program program) { exceptionHandlers = new boolean[program.basicBlockCount()]; for (int i = 0; i < exceptionHandlers.length; ++i) { BasicBlock block = program.basicBlockAt(i); for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { exceptionHandlers[tryCatch.getHandler().getIndex()] = true; } } }
public void apply(Program program) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); for (Instruction insn : block) { if (insn instanceof InitClassInstruction) { if (!filter(((InitClassInstruction) insn).getClassName())) { insn.delete(); } } } } }
/** * Back edges from body are not back edges anymore, instead they point to a copied condition. */ private void moveBackEdges() { BasicBlockMapper mapper = new BasicBlockMapper((int block) -> block == head ? headCopy : block); for (int node : nodes.toArray()) { BasicBlock block = program.basicBlockAt(node); Instruction last = block.getLastInstruction(); if (last != null) { last.acceptVisitor(mapper); } } }
private int[] getInputCount(Program program) { int[] inputCount = new int[program.variableCount()]; for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); for (Phi phi : block.getPhis()) { inputCount[phi.getReceiver().getIndex()] = phi.getIncomings().size(); } } return inputCount; }
public void rename(Program program) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock basicBlock = program.basicBlockAt(i); for (Instruction insn : basicBlock) { insn.acceptVisitor(this); } for (TryCatchBlock tryCatch : basicBlock.getTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { tryCatch.setExceptionType(classNameMapper.map(tryCatch.getExceptionType())); } } } }
public void apply(MethodReader method, Program program) { ClassReader cls = classes.get(method.getOwnerName()); boolean hasClinit = cls.getMethod(clinitDescriptor) != null; if (needsClinitCall(method) && hasClinit) { BasicBlock entryBlock = program.basicBlockAt(0); InitClassInstruction initInsn = new InitClassInstruction(); initInsn.setClassName(method.getOwnerName()); entryBlock.addFirst(initInsn); } }
private Variable box(Variable var, Class<?> boxed, Class<?> primitive) { Program program = MetaprogrammingImpl.generator.getProgram(); BasicBlock block = program.basicBlockAt(0); InvokeInstruction insn = new InvokeInstruction(); insn.setType(InvocationType.SPECIAL); insn.setMethod(new MethodReference(boxed, "valueOf", primitive, boxed)); insn.setArguments(var); var = program.createVariable(); insn.setReceiver(var); block.add(insn); return var; } }