private void compileTemplates(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) { Enumeration templates = _namedTemplates.keys(); while (templates.hasMoreElements()) { final Template template = (Template)templates.nextElement(); compileNamedTemplate(template, classGen); } templates = _neededTemplates.keys(); while (templates.hasMoreElements()) { final Template template = (Template)templates.nextElement(); if (template.hasContents()) { // !!! TODO templates both named and matched InstructionList til = template.compile(classGen, methodGen); til.append(new GOTO_W(next)); _templateILs.put(template, til); _templateIHs.put(template, til.getStart()); } else { // empty template _templateIHs.put(template, next); } } }
private void compileTemplateCalls(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next, int min, int max){ Enumeration templates = _neededTemplates.keys(); while (templates.hasMoreElements()) { final Template template = (Template)templates.nextElement(); final int prec = template.getImportPrecedence(); if ((prec >= min) && (prec < max)) { if (template.hasContents()) { InstructionList til = template.compile(classGen, methodGen); til.append(new GOTO_W(next)); _templateILs.put(template, til); _templateIHs.put(template, til.getStart()); } else { // empty template _templateIHs.put(template, next); } } } }
public boolean preScreen(MethodGen mg) { ConstantPoolGen cpg = mg.getConstantPool(); int lockCount = mg.isSynchronized() ? 1 : 0; boolean sawWaitOrNotify = false; InstructionHandle handle = mg.getInstructionList().getStart(); while (handle != null && !(lockCount >= 2 && sawWaitOrNotify)) { Instruction ins = handle.getInstruction(); if (ins instanceof MONITORENTER) { ++lockCount; } else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins; String methodName = inv.getMethodName(cpg); if ("wait".equals(methodName) || methodName.startsWith("notify")) { sawWaitOrNotify = true; } } handle = handle.getNext(); } return lockCount >= 2 && sawWaitOrNotify; }
for(InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) { Instruction inst = ih.getInstruction(); if(inst instanceof BranchInstruction) {
InstructionHandle handle = methodGen.getInstructionList().getStart(); while (handle != null) { int bytecodeOffset = handle.getPosition();
@Override public void build() throws CFGBuilderException { InstructionList instructionList = methodGen.getInstructionList(); optimize(instructionList); topLevelSubroutine = new Subroutine(instructionList.getStart()); subroutineWorkList.add(topLevelSubroutine); // Build top level subroutine and all JSR subroutines while (!subroutineWorkList.isEmpty()) { Subroutine subroutine = subroutineWorkList.removeFirst(); if (DEBUG) { System.out.println("Starting subroutine " + subroutine.getStartInstruction()); } build(subroutine); } // Inline everything into the top level subroutine cfg = inlineAll(); // Add a NOP instruction to the entry block. // This allows analyses to construct a Location // representing the entry to the method. BasicBlock entryBlock = cfg.getEntry(); InstructionList il = new InstructionList(); entryBlock.addInstruction(il.append(new NOP())); if (VERIFY_INTEGRITY) { cfg.checkIntegrity(); } if (true) { cfg.checkIntegrity(); } }
lvgStart = getInstructionList().getStart();
private void build(MethodGen methodGen) { CodeExceptionGen[] handlerList = methodGen.getExceptionHandlers(); // Map handler start instructions to the actual exception handlers for (CodeExceptionGen exceptionHandler : handlerList) { addExceptionHandler(exceptionHandler); } // For each instruction, determine which handlers it can reach InstructionHandle handle = methodGen.getInstructionList().getStart(); while (handle != null) { int offset = handle.getPosition(); handlerLoop: for (CodeExceptionGen exceptionHandler : handlerList) { int startOfRange = exceptionHandler.getStartPC().getPosition(); int endOfRange = exceptionHandler.getEndPC().getPosition(); if (offset >= startOfRange && offset <= endOfRange) { // This handler is reachable from the instruction addHandler(handle, exceptionHandler); // If this handler handles all exception types // i.e., an ANY handler, or catch(Throwable...), // then no further (lower-priority) // handlers are reachable from the instruction. if (Hierarchy.isUniversalExceptionHandler(exceptionHandler.getCatchType())) { break handlerLoop; } } } handle = handle.getNext(); } }
final BranchHandle loop = ilLoop.append(new GOTO_W(null)); final InstructionHandle ihLoop = ilLoop.getStart(); InstructionHandle ihRecurse = ilRecurse.getStart(); InstructionHandle ihText = ilText.getStart(); loop.setTarget(_idxTestSeq.compile(classGen, methodGen, body.getStart())); ilKey = _idxTestSeq.getInstructionList(); loop.setTarget(body.getStart()); isNamespace, isAttribute, false, ihElem); if (nsElem != null) elemNamespaceHandle = nsElem.getStart(); isNamespace, isAttribute, true, ihAttr); if (nsAttr != null) attrNamespaceHandle = nsAttr.getStart();
final InstructionHandle ihLoop = ilLoop.getStart(); InstructionHandle ihRecurse = ilRecurse.getStart(); InstructionHandle ihText = ilText.getStart(); isNamespace, isAttribute, false, ihElem); if (nsElem != null) elemNamespaceHandle = nsElem.getStart(); true, ihAttr); InstructionHandle attrNamespaceHandle = ihAttr; if (nsAttr != null) attrNamespaceHandle = nsAttr.getStart();
ConstantPoolGen cpg = getConstantPoolGen(analysisCache, descriptor.getClassDescriptor()); for (InstructionHandle handle = il.getStart(); handle != null; handle = handle.getNext()) { Instruction ins = handle.getInstruction(); short opcode = ins.getOpcode();
InstructionHandle ch = newIL.getStart();
public void optimize(InstructionList instructionList) { InstructionHandle head = instructionList.getStart();
fail = il.getStart();
/** * Start search beginning from the start of the given instruction list. * * @param pattern * the instruction pattern to search for, where case is ignored * @return iterator of matches where e.nextElement() returns an array of * instruction handles describing the matched area */ public final Iterator<InstructionHandle[]> search( final String pattern ) { return search(pattern, il.getStart(), null); }
/** * Start search beginning from the start of the given instruction list. * * @param pattern the instruction pattern to search for, where case is ignored * @return iterator of matches where e.nextElement() * returns an array of instruction handles describing the matched * area */ public final Iterator search(String pattern) { return search(pattern, il.getStart(), null); }
/** * Start search beginning from the start of the given instruction list. * Check found matches with the constraint object. * * @param pattern the instruction pattern to search for, case is ignored * @param constraint constraints to be checked on matching code * @return instruction handle or `null' if the match failed */ public final Iterator search(String pattern, CodeConstraint constraint) { return search(pattern, il.getStart(), constraint); }
/** * Start search beginning from the start of the given instruction list. Check * found matches with the constraint object. * * @param pattern * the instruction pattern to search for, case is ignored * @param constraint * constraints to be checked on matching code * @return instruction handle or `null' if the match failed */ public final Iterator<InstructionHandle[]> search( final String pattern, final CodeConstraint constraint ) { return search(pattern, il.getStart(), constraint); }
public Method injection(final JavaClass clazz, Method method, final ConstantPoolGen cp, final int firstStringOffset) { final MethodGen methodGen = new MethodGen(method, clazz.getClassName(), cp); final InstructionList instructionList = methodGen.getInstructionList(); instructionList.insert(instructionList.getStart(), makeWillBeAddedInstructionList(methodGen, firstStringOffset)); methodGen.setMaxStack(); methodGen.setMaxLocals(); method = methodGen.getMethod(); instructionList.dispose(); return method; }