Java Code Examples for org.apache.bcel.generic.InstructionList#getStart()

The following examples show how to use org.apache.bcel.generic.InstructionList#getStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BetterCFGBuilder2.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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()));

    cfg.checkIntegrity();
}
 
Example 2
Source File: BCELPerfTest.java    From annotation-tools with MIT License 5 votes vote down vote up
byte[] nullAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        boolean lv = ms[j].getLocalVariableTable() == null;
        boolean ln = ms[j].getLineNumberTable() == null;
        if (lv) {
            mg.removeLocalVariables();
        }
        if (ln) {
            mg.removeLineNumbers();
        }
        mg.stripAttributes(skipDebug);
        InstructionList il = mg.getInstructionList();
        if (il != null) {
            InstructionHandle ih = il.getStart();
            while (ih != null) {
                ih = ih.getNext();
            }
            if (compute) {
                mg.setMaxStack();
                mg.setMaxLocals();
            }
        }
        cg.replaceMethod(ms[j], mg.getMethod());
    }
    return cg.getJavaClass().getBytes();
}
 
Example 3
Source File: BCELPerfTest.java    From annotation-tools with MIT License 5 votes vote down vote up
byte[] nullAdaptClass(final InputStream is, final String name)
        throws Exception
{
    JavaClass jc = new ClassParser(is, name + ".class").parse();
    ClassGen cg = new ClassGen(jc);
    ConstantPoolGen cp = cg.getConstantPool();
    Method[] ms = cg.getMethods();
    for (int j = 0; j < ms.length; ++j) {
        MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
        boolean lv = ms[j].getLocalVariableTable() == null;
        boolean ln = ms[j].getLineNumberTable() == null;
        if (lv) {
            mg.removeLocalVariables();
        }
        if (ln) {
            mg.removeLineNumbers();
        }
        mg.stripAttributes(skipDebug);
        InstructionList il = mg.getInstructionList();
        if (il != null) {
            InstructionHandle ih = il.getStart();
            while (ih != null) {
                ih = ih.getNext();
            }
            if (compute) {
                mg.setMaxStack();
                mg.setMaxLocals();
            }
        }
        cg.replaceMethod(ms[j], mg.getMethod());
    }
    return cg.getJavaClass().getBytes();
}
 
Example 4
Source File: ASTLetExpr.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Fifth pass, produce Java byte code.
 */
@Override
public void byte_code(final InstructionList il, final MethodGen method, final ConstantPoolGen cp) {
  final int size = idents.length;
  final LocalVariableGen[] l = new LocalVariableGen[size];

  for(int i=0; i < size; i++) {
    final String           ident = idents[i].getName();
    final Variable         entry = (Variable)env.get(ident);
    final Type             t     = BasicType.getType((byte)idents[i].getType());
    final LocalVariableGen lg    = method.addLocalVariable(ident, t, null, null);
    final int              slot  = lg.getIndex();

    entry.setLocalVariable(lg);
    InstructionHandle start = il.getEnd();
    exprs[i].byte_code(il, method, cp);
    start = (start == null)? il.getStart() : start.getNext();
    lg.setStart(start);
    il.append(new ISTORE(slot));     ASTFunDecl.pop();
    l[i] = lg;
  }

  body.byte_code(il, method, cp);
  final InstructionHandle end = il.getEnd();
  for(int i=0; i < size; i++) {
      l[i].setEnd(end);
  }
}