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; }
if (methodGen == null || methodGen.getInstructionList() == null) { continue; //No instruction .. nothing to do for (Iterator itIns = methodGen.getInstructionList().iterator();itIns.hasNext();) { Instruction inst = ((InstructionHandle) itIns.next()).getInstruction();
return false; InstructionList il = methodGen.getInstructionList();
return NONE_FINALLY_INFO; InstructionList il = methodGen.getInstructionList(); BitSet branchTargets = new BitSet(); for(InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
/** * Factory method for creating a source line annotation describing an entire * method. * * @param methodGen * the method being visited * @return the SourceLineAnnotation, or null if we do not have line number * information for the method */ public static SourceLineAnnotation fromVisitedMethod(MethodGen methodGen, String sourceFile) { LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); int codeSize = methodGen.getInstructionList().getLength(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, 0, codeSize - 1); } return forEntireMethod(className, sourceFile, lineNumberTable, codeSize); }
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(); } }
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException { MethodGen methodGen = classContext.getMethodGen(m); ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = classContext.getCFG(m); if (methodGen == null || methodGen.getInstructionList() == null) { return; //No instruction .. nothing to do } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location location = i.next(); Instruction inst = location.getHandle().getInstruction(); if (inst instanceof InvokeInstruction) { InvokeInstruction invoke = (InvokeInstruction) inst; String methodName = invoke.getMethodName(cpg); if ("enableDefaultTyping".equals(methodName)) { JavaClass clz = classContext.getJavaClass(); bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY) .addClass(clz) .addMethod(clz, m) .addCalledMethod(cpg, invoke) .addSourceLine(classContext, m, location) ); } } } }
BitSet assertionBlocks = new BitSet(); MethodGen methodGen = cfg.getMethodGen(); Iterator<InstructionHandle> iterator = methodGen.getInstructionList().iterator(); while(iterator.hasNext()) { InstructionHandle ih = iterator.next();
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(); } }
InstructionHandle firstHandle = methodGen.getInstructionList().findHandle(first); InstructionHandle secondHandle = methodGen.getInstructionList().findHandle(second); while(true) { if(firstHandle == null || secondHandle == null) {
return null; InstructionList il = methodGen.getInstructionList();
/** * Subsume node-set into ObjectType. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ObjectType type) { methodGen.getInstructionList().append(NOP); }
/** * Expects a boolean on the stack and pushes a real. The value "true" is * converted to 1.0 and the value "false" to 0.0. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, RealType type) { methodGen.getInstructionList().append(I2D); }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); il.append(new PUSH(cpg, _value)); }
/** * Translate this attribute value into JVM bytecodes that pushes the * attribute value onto the JVM's stack. * @param classGen BCEL Java class generator * @param methodGen BCEL Java method generator */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new PUSH(cpg, _value)); } }
/** * Calls to 'element-available' are resolved at compile time since * the namespaces declared in the stylsheet are not available at run * time. Consequently, arguments to this function must be literals. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final boolean result = getResult(); methodGen.getInstructionList().append(new PUSH(cpg, result)); } }
/** @return deep copy of this method */ public MethodGen copy(String class_name, ConstantPoolGen cp) { Method m = ((MethodGen)clone()).getMethod(); MethodGen mg = new MethodGen(m, class_name, this.cp); if(this.cp != cp) { mg.setConstantPool(cp); mg.getInstructionList().replaceConstantPool(this.cp, cp); } return mg; } }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); argument(0).translate(classGen, methodGen); il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS, "ceil", "(D)D"))); } }
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; }