public void setMaxLocals() { // Get the current number of local variable slots int maxLocals = super.getMaxLocals(); // Get numer of actual variables final LocalVariableGen[] localVars = super.getLocalVariables(); if (localVars != null) { if (localVars.length > maxLocals) maxLocals = localVars.length; } // We want at least 5 local variable slots (for parameters) if (maxLocals < 5) maxLocals = 5; super.setMaxLocals(maxLocals); }
public void setMaxLocals() { // Get the current number of local variable slots int maxLocals = super.getMaxLocals(); // Get numer of actual variables final LocalVariableGen[] localVars = super.getLocalVariables(); if (localVars != null) { if (localVars.length > maxLocals) maxLocals = localVars.length; } // We want at least 5 local variable slots (for parameters) if (maxLocals < 5) maxLocals = 5; super.setMaxLocals(maxLocals); }
public void setMaxLocals() { // Get the current number of local variable slots int maxLocals = super.getMaxLocals(); // Get numer of actual variables final LocalVariableGen[] localVars = super.getLocalVariables(); if (localVars != null) { if (localVars.length > maxLocals) maxLocals = localVars.length; } // We want at least 5 local variable slots (for parameters) if (maxLocals < 5) maxLocals = 5; super.setMaxLocals(maxLocals); }
public void setMaxLocals() { // Get the current number of local variable slots int maxLocals = super.getMaxLocals(); // Get numer of actual variables final LocalVariableGen[] localVars = super.getLocalVariables(); if (localVars != null) { if (localVars.length > maxLocals) maxLocals = localVars.length; } // We want at least 5 local variable slots (for parameters) if (maxLocals < 5) maxLocals = 5; super.setMaxLocals(maxLocals); }
private void createMethod_2() { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(ACC_STATIC | ACC_SYNTHETIC, Type.BOOLEAN, Type.NO_ARGS, new String[] { }, "access$0", "StopThread", il, _cp); InstructionHandle ih_0 = il.append(_factory.createFieldAccess("StopThread", "stopRequested", Type.BOOLEAN, Constants.GETSTATIC)); il.append(_factory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
public void fixStack() { for (ClassGen cg : cgs.values()) { for (Method method : cg.getMethods()) { MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); mg.removeNOPs(); mg.setMaxLocals(); mg.setMaxStack(); cg.replaceMethod(method, mg.getMethod()); logger.debug(String.format("Reset MaxStack and MaxLocals in %s.%s", cg.getClassName(), mg.getName())); } } }
public void replaceCheckMethod() { ClassGen cg = cgs.get(AuthClass); Method method = cg.getMethods()[0]; MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool()); InstructionList list = new InstructionList(); list.append(new ICONST(1)); list.append(new IRETURN()); mg.removeExceptionHandlers(); mg.removeLineNumbers(); mg.removeLocalVariables(); mg.removeExceptions(); mg.setInstructionList(list); mg.setMaxLocals(); mg.setMaxStack(); cg.replaceMethod(method, mg.getMethod()); }
private void createMethod_getARGV() { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, getObjectType(Object.class), new Type[] {}, new String[] {}, "getARGV", classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(factory.createFieldAccess(classname, argv_field, getObjectType(Object.class), Constants.GETFIELD)); tmpIl.append(InstructionFactory.createReturn(getObjectType(Object.class))); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createSetMethod(String method_name, String field_name, Class field_type) { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, Type.VOID, buildArgs(new Class[] {field_type}), new String[] {"arg"}, method_name, classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(InstructionConstants.ALOAD_1); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.PUTFIELD)); tmpIl.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createResetMethod(String method_name, String field_name) { InstructionList tmpIl = new InstructionList(); // no-arg method MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, Type.VOID, buildArgs(new Class[] {}), new String[] {}, method_name, classname, tmpIl, cp); // implement: setXX(ZERO) tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(factory.createFieldAccess(classname, "ZERO", getObjectType(Integer.class), Constants.GETSTATIC)); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.PUTFIELD)); tmpIl.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
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; }
private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] { }, "test3", TEST_PACKAGE+".TestReturn03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(InstructionFactory.createReturn(Type.OBJECT)); method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); } }
private void generateEqualsMethod(String generatedClassName) { /* public boolean equals(Object o) { * return stubHelper.isEquals(this,o); * } */ InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.BOOLEAN, new Type[]{Type.OBJECT}, new String[]{"arg0"}, "equals", generatedClassName, il, constantsPool); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.GETFIELD)); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "isEquals", Type.BOOLEAN, new Type[]{Type.OBJECT, Type.OBJECT}, Constants.INVOKEINTERFACE)); il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
private void createGetMethod(int method_access, String method_name, String field_name) { InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(method_access | ACC_FINAL, getObjectType(Object.class), new Type[] {}, new String[] {}, method_name, classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); tmpIl.append(factory.createFieldAccess(classname, field_name, getObjectType(Object.class), Constants.GETFIELD)); tmpIl.append(InstructionConstants.DUP); BranchHandle bh = tmpIl.append(new IFNONNULL(null)); // NULL! tmpIl.append(InstructionConstants.POP); // pop the null tmpIl.append(new PUSH(cp, "")); InstructionHandle ih = tmpIl.append(InstructionFactory.createReturn(getObjectType(Object.class))); bh.setTarget(ih); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestArrayAccess04", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestReturn03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestArrayAccess03", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestReturn01", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", TEST_PACKAGE+".TestArrayAccess02", il, _cp); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); }
private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, Type.NO_ARGS, new String[] { }, "foo", TEST_PACKAGE+".TestReturn01", il, _cp); final InstructionHandle ih_0 = il.append(_factory.createNew("java.lang.Object")); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(InstructionConst.DUP); il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); il.append(InstructionConst.NOP); final InstructionHandle ih_8 = il.append(InstructionFactory.createReturn(Type.OBJECT)); Assert.assertNotNull(ih_8); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); } }