int getStartPosOfBody(CodeAttribute ca) throws CannotCompileException { CodeIterator ci = ca.iterator(); try { ci.skipConstructor(); return ci.next(); } catch (BadBytecode e) { throw new CannotCompileException(e); } }
/** * Returns true if this constructor calls a constructor * of the super class. This method returns false if it * calls another constructor of this class by <code>this()</code>. */ public boolean callsSuper() throws CannotCompileException { CodeAttribute codeAttr = methodInfo.getCodeAttribute(); if (codeAttr != null) { CodeIterator it = codeAttr.iterator(); try { int index = it.skipSuperConstructor(); return index >= 0; } catch (BadBytecode e) { throw new CannotCompileException(e); } } return false; }
public BasicBlock[] make(MethodInfo minfo) throws BadBytecode { CodeAttribute ca = minfo.getCodeAttribute(); if (ca == null) return null; CodeIterator ci = ca.iterator(); return make(ci, 0, ci.getCodeLength(), ca.getExceptionTable()); }
@Override int getStartPosOfBody(CodeAttribute ca) throws CannotCompileException { CodeIterator ci = ca.iterator(); try { ci.skipConstructor(); return ci.next(); } catch (BadBytecode e) { throw new CannotCompileException(e); } }
/** * Prints the bytecode instructions of a given method. */ public void print(CtMethod method) { MethodInfo info = method.getMethodInfo2(); ConstPool pool = info.getConstPool(); CodeAttribute code = info.getCodeAttribute(); if (code == null) return; CodeIterator iterator = code.iterator(); while (iterator.hasNext()) { int pos; try { pos = iterator.next(); } catch (BadBytecode e) { throw new RuntimeException(e); } stream.println(pos + ": " + instructionString(iterator, pos, pool)); } }
/** * Returns true if this constructor calls a constructor * of the super class. This method returns false if it * calls another constructor of this class by <code>this()</code>. */ public boolean callsSuper() throws CannotCompileException { CodeAttribute codeAttr = methodInfo.getCodeAttribute(); if (codeAttr != null) { CodeIterator it = codeAttr.iterator(); try { int index = it.skipSuperConstructor(); return index >= 0; } catch (BadBytecode e) { throw new CannotCompileException(e); } } return false; }
public Subroutine[] scan(MethodInfo method) throws BadBytecode { CodeAttribute code = method.getCodeAttribute(); CodeIterator iter = code.iterator(); subroutines = new Subroutine[code.getCodeLength()]; subTable.clear(); done.clear(); scan(0, iter, null); ExceptionTable exceptions = code.getExceptionTable(); for (int i = 0; i < exceptions.size(); i++) { int handler = exceptions.handlerPc(i); // If an exception is thrown in subroutine, the handler // is part of the same subroutine. scan(handler, iter, subroutines[exceptions.startPc(i)]); } return subroutines; }
/** * Changes the index numbers of the local variables * to append a new parameter. * This method does not update <code>LocalVariableAttribute</code>, * <code>LocalVariableTypeAttribute</code>, * <code>StackMapTable</code>, or <code>StackMap</code>. * These attributes must be explicitly updated. * * @param where the index of the new parameter. * @param size the type size of the new parameter (1 or 2). * * @see LocalVariableAttribute#shiftIndex(int, int) * @see LocalVariableTypeAttribute#shiftIndex(int, int) * @see StackMapTable#insertLocal(int, int, int) * @see StackMap#insertLocal(int, int, int) */ public void insertLocalVar(int where, int size) throws BadBytecode { CodeIterator ci = iterator(); while (ci.hasNext()) shiftIndex(ci, where, size); setMaxLocals(getMaxLocals() + size); }
public BasicBlock[] make(MethodInfo minfo) throws BadBytecode { CodeAttribute ca = minfo.getCodeAttribute(); if (ca == null) return null; CodeIterator ci = ca.iterator(); return make(ci, 0, ci.getCodeLength(), ca.getExceptionTable()); }
public int computeMaxStack() throws BadBytecode { /* d = stack[i] * d == 0: not visited * d > 0: the depth is d - 1 after executing the bytecode at i. * d < 0: not visited. the initial depth (before execution) is 1 - d. */ CodeIterator ci = codeAttr.iterator(); int length = ci.getCodeLength(); int[] stack = new int[length]; constPool = codeAttr.getConstPool(); initStack(stack, codeAttr); boolean repeat; do { repeat = false; for (int i = 0; i < length; ++i) if (stack[i] < 0) { repeat = true; visitBytecode(ci, stack, i); } } while (repeat); int maxStack = 1; for (int i = 0; i < length; ++i) if (stack[i] > maxStack) maxStack = stack[i]; return maxStack - 1; // the base is 1. }
CodeIterator iterator = code.iterator(); while (iterator.hasNext()) { int pos;
public Subroutine[] scan(MethodInfo method) throws BadBytecode { CodeAttribute code = method.getCodeAttribute(); CodeIterator iter = code.iterator(); subroutines = new Subroutine[code.getCodeLength()]; subTable.clear(); done.clear(); scan(0, iter, null); ExceptionTable exceptions = code.getExceptionTable(); for (int i = 0; i < exceptions.size(); i++) { int handler = exceptions.handlerPc(i); // If an exception is thrown in subroutine, the handler // is part of the same subroutine. scan(handler, iter, subroutines[exceptions.startPc(i)]); } return subroutines; }
/** * Returns true if the method body is empty, that is, <code>{}</code>. * It also returns true if the method is an abstract method. */ public boolean isEmpty() { CodeAttribute ca = getMethodInfo2().getCodeAttribute(); if (ca == null) // abstract or native return (getModifiers() & Modifier.ABSTRACT) != 0; CodeIterator it = ca.iterator(); try { return it.hasNext() && it.byteAt(it.next()) == Opcode.RETURN && !it.hasNext(); } catch (BadBytecode e) {} return false; }
private static void insertAuxInitializer(CodeAttribute codeAttr, Bytecode initializer, int stacksize) throws BadBytecode { CodeIterator it = codeAttr.iterator(); int index = it.skipSuperConstructor(); if (index < 0) { index = it.skipThisConstructor(); if (index >= 0) return; // this() is called. // Neither this() or super() is called. } int pos = it.insertEx(initializer.get()); it.insert(initializer.getExceptionTable(), pos); int maxstack = codeAttr.getMaxStack(); if (maxstack < stacksize) codeAttr.setMaxStack(stacksize); }
/** * Returns true if the method body is empty, that is, <code>{}</code>. * It also returns true if the method is an abstract method. */ @Override public boolean isEmpty() { CodeAttribute ca = getMethodInfo2().getCodeAttribute(); if (ca == null) // abstract or native return (getModifiers() & Modifier.ABSTRACT) != 0; CodeIterator it = ca.iterator(); try { return it.hasNext() && it.byteAt(it.next()) == Opcode.RETURN && !it.hasNext(); } catch (BadBytecode e) {} return false; }
CodeIterator iterator = ca.iterator(); int pos = iterator.skipSuperConstructor(); if (pos >= 0) { // not this()
/** * Returns true if the constructor (or static initializer) * is the default one. This method returns true if the constructor * takes some arguments but it does not perform anything except * calling <code>super()</code> (the no-argument constructor of * the super class). */ public boolean isEmpty() { CodeAttribute ca = getMethodInfo2().getCodeAttribute(); if (ca == null) return false; // native or abstract?? // they are not allowed, though. ConstPool cp = ca.getConstPool(); CodeIterator it = ca.iterator(); try { int pos, desc; int op0 = it.byteAt(it.next()); return op0 == Opcode.RETURN // empty static initializer || (op0 == Opcode.ALOAD_0 && it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL && (desc = cp.isConstructor(getSuperclassName(), it.u16bitAt(pos + 1))) != 0 && "()V".equals(cp.getUtf8Info(desc)) && it.byteAt(it.next()) == Opcode.RETURN && !it.hasNext()); } catch (BadBytecode e) {} return false; }
CodeIterator iterator = minfo.getCodeAttribute().iterator(); while (iterator.hasNext()) { try {
private static void removeConsCall(CodeAttribute ca) throws CannotCompileException CodeIterator iterator = ca.iterator(); try { int pos = iterator.skipConstructor();
CodeIterator iterator = ca.iterator(); Bytecode b = new Bytecode(methodInfo.getConstPool(), ca.getMaxStack(), ca.getMaxLocals());