ctorMethod.setMaxStack(2); InstructionHandle ctor_ih_0 = ctor.append(fac.createLoad(Type.OBJECT, 0)); ctor.append(fac.createInvoke(CLASS_NAME_SERIALIZABLE_IMPL, "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); InstructionHandle ctor_ih_4 = ctor.append(fac.createLoad(Type.OBJECT, 0)); ctor.append(fac.createLoad(Type.OBJECT, 1)); ctor.append(fac.createFieldAccess(CLASS_NAME_SERIALIZABLE_IMPL_WITH_VALUE, "value", Type.OBJECT, Constants.PUTFIELD)); getterMethod.setMaxStack(1); InstructionHandle getter_ih_0 = getter.append(fac.createLoad(Type.OBJECT, 0)); InstructionHandle getter_ih_1 = getter.append(fac.createGetField(cg.getClassName(), field.getName(), Type.getType(field.getSignature()))); setterMethod.setMaxStack(2); InstructionHandle setter_ih_0 = setter.append(fac.createLoad(Type.OBJECT, 0)); InstructionHandle setter_ih_1 = setter.append(fac.createLoad(Type.OBJECT, 1)); InstructionHandle setter_ih_2 = setter.append(fac.createPutField(cg.getClassName(), field.getName(), Type.getType(field.getSignature())));
@SuppressWarnings("unused") // Called using reflection private Instruction createInstructionAload(Element inst) throws IllegalXMLVMException { String t= inst.getAttributeValue("type"); Type type= parseTypeString(t); int idx= Integer.parseInt(inst.getAttributeValue("index")); return factory.createLoad(type, idx); }
private InstructionHandle JVMTools_getLocalVariable(Class vartype, String varname) { Integer I = local_vars.get(varname); if (I == null) { throw new Error(varname + " not found as a local variable"); } return il.append(InstructionFactory.createLoad(getObjectType(vartype), I)); }
private void addPartialParamCall(String func_name, int num_formal_params, int num_actual_params) { // condition the argument parameters List<Class> arg_classes = new ArrayList<Class>(); List<String> arg_names = new ArrayList<String>(); Map<String, Integer> tmpLocalVars = new HashMap<String, Integer>(); for (int i = num_actual_params - 1; i >= 0; --i) { arg_classes.add(Object.class); arg_names.add("locals_" + i); tmpLocalVars.put("locals_" + i, tmpLocalVars.size() + 1); } InstructionList tmpIl = new InstructionList(); MethodGen method = new MethodGen(ACC_PUBLIC | ACC_FINAL, getObjectType(Object.class), buildArgs(toClassArray(arg_classes)), toStringArray(arg_names), "FUNC_" + func_name, classname, tmpIl, cp); tmpIl.append(InstructionConstants.ALOAD_0); arg_classes.clear(); for (int i = num_formal_params - 1; i >= 0; --i) { arg_classes.add(Object.class); if (i >= num_actual_params) { tmpIl.append(InstructionConstants.ACONST_NULL); } else { tmpIl.append(InstructionFactory.createLoad(getObjectType(Object.class), tmpLocalVars.get("locals_" + i))); } } tmpIl.append(factory.createInvoke(classname, "FUNC_" + func_name, getObjectType(Object.class), buildArgs(toClassArray(arg_classes)), Constants.INVOKEVIRTUAL)); tmpIl.append(InstructionFactory.createReturn(getObjectType(Object.class))); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); tmpIl.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(); }
constPool); il.append(iFactory.createLoad(INVOCATION_HANDLER_T, 0)); il.append(iFactory.createInvoke(superClassName, CTOR_MN, Type.NO_ARGS, Constants.INVOKESPECIAL)); il.append(iFactory.createLoad(PROXY_CLASS_T, 0)); il.append(iFactory.createLoad(INVOCATION_HANDLER_T, 1)); il.append(iFactory.createPutField(proxyClassName, INVOCATION_HANDLER_FN, INVOCATION_HANDLER_T)); il.append(iFactory.createReturn(Type.VOID));
/** * Method createConstructor. * This method adds a constructor that takes in a StubHelper Instance * * @param generatedClassName the stub class name */ protected void createConstructor(String generatedClassName) { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[]{new ObjectType("org.codehaus.jremoting.client.StubHelper")}, new String[]{"arg0"}, "<init>", generatedClassName, il, constantsPool); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createFieldAccess(generatedClassName, "stubHelper", new ObjectType("org.codehaus.jremoting.client.StubHelper"), Constants.PUTFIELD)); il.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
/** * Add method * <pre> * public Long jRemotingGetReferenceID(Object factoryThatIsAsking) { * return stubHelper.getReference(factoryThatIsAsking); * } * </pre> * * @param generatedClassName the generated class name */ protected void createGetReferenceIDMethod(String generatedClassName) { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_PUBLIC, new ObjectType("java.lang.Long"), new Type[]{Type.OBJECT}, new String[]{"arg0"}, "jRemotingGetReferenceID", 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, 1)); il.append(factory.createInvoke("org.codehaus.jremoting.client.StubHelper", "getReference", new ObjectType("java.lang.Long"), new Type[]{Type.OBJECT}, Constants.INVOKEINTERFACE)); il.append(InstructionFactory.createReturn(Type.OBJECT)); method.setMaxStack(); method.setMaxLocals(); classGen.addMethod(method.getMethod()); il.dispose(); }
/** * generate an implementation of * <pre> * * <code> * public InvocationHandler getInvocationHandler() { * return this.invocationHandler; * } * </code> * * </pre> */ public Method createGetInvocationHandler() { MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, INVOCATION_HANDLER_T, Type.NO_ARGS, null, GET_INVOCATION_HANDLER_MN, proxyClassName, il, constPool); il.append(iFactory.createLoad(PROXY_CLASS_T, 0)); il.append(iFactory.createGetField(proxyClassName, INVOCATION_HANDLER_FN, INVOCATION_HANDLER_T)); il.append(iFactory.createReturn(INVOCATION_HANDLER_T)); mg.stripAttributes(true); mg.setMaxStack(); mg.setMaxLocals(); return getMethodAndTidyup(mg); }
BranchInstruction b1 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null); il.append(b1); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createCheckCast(new ObjectType("java.lang.RuntimeException"))); il.append(InstructionConstants.ATHROW); InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.Error")))); BranchInstruction b2 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null); il.append(b2); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createCheckCast(new ObjectType("java.lang.Error"))); il.append(InstructionConstants.ATHROW); InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createInvoke("java.lang.Throwable", "printStackTrace", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createNew("org.codehaus.jremoting.client.InvocationException")); il.append(new PUSH(constantsPool, "Should never get here: ")); il.append(factory.createInvoke("java.lang.StringBuffer", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL));
/** * Creates a method class$(String) which is used * during SomeClass.class instruction * * @param generatedClassName the instance class name */ protected void createHelperMethodForDotClassCalls(String generatedClassName) { InstructionList il = new InstructionList(); MethodGen method = new MethodGen(Constants.ACC_STATIC, new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, new String[]{"arg0"}, "class$", generatedClassName, il, constantsPool); InstructionHandle ih0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createInvoke("java.lang.Class", "forName", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC)); InstructionHandle ih4 = il.append(InstructionFactory.createReturn(Type.OBJECT)); InstructionHandle ih5 = il.append(InstructionFactory.createStore(Type.OBJECT, 1)); il.append(factory.createNew("java.lang.NoClassDefFoundError")); il.append(InstructionConstants.DUP); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionConstants.ATHROW); method.addExceptionHandler(ih0, ih4, ih5, new ObjectType("java.lang.ClassNotFoundException")); method.setMaxStack(); method.setMaxLocals(); classGen.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, new Type[] { Type.OBJECT }, new String[] { "arg0" }, "test", TEST_PACKAGE+".TestArrayAccess03", il, _cp); final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createNewArray(new ObjectType(TEST_PACKAGE+".TestArrayAccess03"), (short) 1)); il.append(InstructionFactory.createStore(Type.OBJECT, 1)); final InstructionHandle ih_5 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); Assert.assertNotNull(ih_5); // TODO why is this not used il.append(new PUSH(_cp, 0)); il.append(_factory.createNew(TEST_PACKAGE+".TestArrayAccess03")); il.append(InstructionConst.DUP); il.append(_factory.createInvoke(TEST_PACKAGE+".TestArrayAccess03", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); il.append(InstructionConst.AASTORE); final InstructionHandle ih_15 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_15); // 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+".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(); }
static void emitOneArgConstructor(ClassGen stubClass, FieldGen handlerField) { String stubClassName = stubClass.getClassName(); ConstantPoolGen cp = stubClass.getConstantPool(); InstructionList il = new InstructionList(); Type[] args = new Type[] { handlerField.getType() }; MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, args, null, "<init>", stubClassName, il, cp); InstructionFactory fac = new InstructionFactory(stubClass, cp); // call super-constructor il.append(InstructionFactory.createThis()); il.append(fac.createInvoke(stubClass.getSuperclassName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); // push this again... il.append(InstructionFactory.createThis()); // push the handler il.append(InstructionFactory.createLoad(handlerField.getType(), 1)); // put handlerField il.append(new PUTFIELD(cp.addFieldref(stubClassName, handlerField .getName(), handlerField.getSignature()))); // return il.append(InstructionConstants.RETURN); // compute stack and locals... mg.setMaxStack(); mg.setMaxLocals(); stubClass.addMethod(mg.getMethod()); }
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[] { }, "test", TEST_PACKAGE+".TestArrayAccess02", il, _cp); final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createNewArray(new ObjectType(TEST_PACKAGE+".TestArrayAccess02"), (short) 1)); il.append(InstructionFactory.createStore(Type.OBJECT, 0)); final InstructionHandle ih_5 = il.append(new PUSH(_cp, 1)); Assert.assertNotNull(ih_5); // TODO why is this not used il.append(_factory.createNewArray(Type.STRING, (short) 1)); il.append(InstructionFactory.createStore(Type.OBJECT, 1)); final InstructionHandle ih_10 = il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); Assert.assertNotNull(ih_10); // TODO why is this not used il.append(new PUSH(_cp, 0)); il.append(_factory.createNew(TEST_PACKAGE+".TestArrayAccess02")); il.append(InstructionConst.DUP); il.append(_factory.createInvoke(TEST_PACKAGE+".TestArrayAccess02", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); il.append(InstructionConst.AASTORE); final InstructionHandle ih_20 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_20); // 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, new Type[] { Type.OBJECT }, new String[] { "arg0" }, "test", TEST_PACKAGE+".TestArrayAccess04", il, _cp); final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1)); Assert.assertNotNull(ih_0); // TODO why is this not used il.append(_factory.createNewArray(Type.OBJECT, (short) 1)); il.append(InstructionFactory.createStore(Type.OBJECT, 1)); final InstructionHandle ih_5 = il.append(new PUSH(_cp, 1)); Assert.assertNotNull(ih_5); // TODO why is this not used il.append(InstructionFactory.createStore(Type.INT, 2)); final InstructionHandle ih_7 = il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); Assert.assertNotNull(ih_7); // TODO why is this not used il.append(new PUSH(_cp, 0)); il.append(InstructionFactory.createLoad(Type.INT, 2)); il.append(InstructionConst.AASTORE); final InstructionHandle ih_11 = il.append(InstructionFactory.createReturn(Type.VOID)); Assert.assertNotNull(ih_11); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); _cg.addMethod(method.getMethod()); il.dispose(); } }