/** * Calculate and set the maximum stack depth needed for * the instructions used. * * @see #setMaxStack */ public void calculateMaxStack() { int stack = 0; int max = 0; ExceptionHandler[] handlers = getExceptionHandlers(); Instruction ins; for (CodeEntry entry = _head.next; entry != _tail; entry = entry.next) { ins = (Instruction) entry; stack += ins.getStackChange(); // if this is the start of a try, the exception will be placed // on the stack for (int j = 0; j < handlers.length; j++) if (handlers[j].getTryStart() == ins) stack++; if (stack > max) max = stack; } setMaxStack(max); }
/** * Calculate and set the maximum stack depth needed for * the instructions used. * * @see #setMaxStack */ public void calculateMaxStack() { int stack = 0; int max = 0; ExceptionHandler[] handlers = getExceptionHandlers(); Instruction ins; for (CodeEntry entry = _head.next; entry != _tail; entry = entry.next) { ins = (Instruction) entry; stack += ins.getStackChange(); // if this is the start of a try, the exception will be placed // on the stack for (int j = 0; j < handlers.length; j++) if (handlers[j].getTryStart() == ins) stack++; if (stack > max) max = stack; } setMaxStack(max); }
/** * Convenience method to add a default constructor to this class. * If a default constructor already exists, this method will return it * without modification. * This method can only be called if the superclass has been set. * * @return the default constructor */ public BCMethod addDefaultConstructor() { BCMethod method = getDeclaredMethod("<init>", (String[]) null); if (method != null) return method; method = declareMethod("<init>", void.class, null); Code code = method.getCode(true); code.setMaxStack(1); code.setMaxLocals(1); code.xload().setThis(); code.invokespecial() .setMethod(getSuperclassName(), "<init>", "void", null); code.vreturn(); return method; }
/** * Convenience method to add a default constructor to this class. * If a default constructor already exists, this method will return it * without modification. * This method can only be called if the superclass has been set. * * @return the default constructor */ public BCMethod addDefaultConstructor() { BCMethod method = getDeclaredMethod("<init>", (String[]) null); if (method != null) return method; method = declareMethod("<init>", void.class, null); Code code = method.getCode(true); code.setMaxStack(1); code.setMaxLocals(1); code.xload().setThis(); code.invokespecial() .setMethod(getSuperclassName(), "<init>", "void", null); code.vreturn(); return method; }
code.setMaxStack(3); code.setMaxLocals(2);
code.setMaxStack(3); code.setMaxLocals(2);