Examples of CodeAttribute


Examples of org.apache.jdo.impl.enhancer.classfile.CodeAttribute

        insn = insn.append(Insn.create(opc_iconst_0));

        // end of method body
        insn = insn.append(Insn.create(opc_ireturn));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                2, // maxStack
                                2, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

Examples of org.apache.jdo.impl.enhancer.classfile.CodeAttribute

        insn = insn.append(Insn.create(opc_aconst_null));

        // end of method body
        insn = insn.append(Insn.create(opc_areturn));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                2, // maxStack
                                2, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

Examples of org.apache.jdo.impl.enhancer.classfile.CodeAttribute

        insn = insn.append(Insn.create(opc_if_icmplt, loopbody));

        // end of method body
        insn = insn.append(Insn.create(opc_return));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                3, // maxStack
                                4, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());
View Full Code Here

Examples of org.gjt.jclasslib.structures.attributes.CodeAttribute

        mi1.setAccessFlags(AccessFlags.ACC_PUBLIC);
        mi1.setNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf, "<init>", 0));
        mi1.setDescriptorIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
                "()V",
                0));
        CodeAttribute ca1 = new CodeAttribute();
        ca1.setAttributeNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
                CodeAttribute.ATTRIBUTE_NAME,
                0));
        ca1.setCode(ByteCodeWriter.writeByteCode(Arrays.asList(new org.gjt.jclasslib.bytecode.AbstractInstruction[] {
            new SimpleInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_ALOAD_0),
            new ImmediateShortInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_INVOKESPECIAL,
                    ConstantPoolUtil.addConstantMethodrefInfo(cf,
                            "java/lang/Object",
                            "<init>",
                            "()V",
                            0)),
            new SimpleInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_RETURN) })));
        ca1.setMaxStack(1);
        ca1.setMaxLocals(1);
        mi1.setAttributes(new AttributeInfo[] { ca1 });

        ConstantStringInfo s = new ConstantStringInfo();
        s.setStringIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
                "Hello world!",
                0));

        org.gjt.jclasslib.structures.MethodInfo mi2 = new org.gjt.jclasslib.structures.MethodInfo();
        mi2.setAccessFlags(AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC);
        mi2.setNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf, "main", 0));
        mi2.setDescriptorIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
                "([Ljava/lang/String;)V",
                0));
        CodeAttribute ca2 = new CodeAttribute();
        ca2.setAttributeNameIndex(ConstantPoolUtil.addConstantUTF8Info(cf,
                CodeAttribute.ATTRIBUTE_NAME,
                0));
        ca2.setCode(ByteCodeWriter.writeByteCode(Arrays.asList(new org.gjt.jclasslib.bytecode.AbstractInstruction[] {
            new ImmediateShortInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_GETSTATIC,
                    ConstantPoolUtil.addConstantFieldrefInfo(cf,
                            "java/lang/System",
                            "out",
                            "Ljava/io/PrintStream;",
                            0)),
            new ImmediateByteInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_LDC,
                    false,
                    ConstantPoolUtil.addConstantPoolEntry(cf, s, 0)),
            new ImmediateShortInstruction(org.gjt.jclasslib.bytecode.Opcodes.OPCODE_INVOKEVIRTUAL,
                    ConstantPoolUtil.addConstantMethodrefInfo(cf,
                            "java/io/PrintStream",
                            "println",
                            "(Ljava/lang/String;)V",
                            0)) })));
        ca2.setMaxStack(2);
        ca2.setMaxLocals(1);
        mi2.setAttributes(new AttributeInfo[] { ca2 });

        cf.setMethods(new org.gjt.jclasslib.structures.MethodInfo[] { mi1, mi2 });
        cf.setAttributes(new AttributeInfo[] { sa });
View Full Code Here

Examples of org.jboss.classfilewriter.code.CodeAttribute

         */
        // we simply want to load the corresponding identifier
        // and then forward it to the dispatcher
        @Override
        public void overrideMethod(ClassMethod method, Method superclassMethod) {
            CodeAttribute ca = method.getCodeAttribute();
            // first we need to check the constructed field
            ca.aload(0);
            ca.getfield(getClassName(), CONSTRUCTED_GUARD, "Z");
            // if the object has not been constructed yet invoke the superclass version of the method
            BranchEnd end = ca.ifne();
            ca.aload(0);
            ca.loadMethodParameters();
            ca.invokespecial(getSuperClassName(), method.getName(), method.getDescriptor());
            ca.returnInstruction();
            // normal invocation path begins here
            ca.branchEnd(end);
            ca.aload(0);
            ca.getfield(getClassName(), INVOCATION_HANDLER_FIELD, InvocationHandler.class);
            ca.aload(0);
            loadMethodIdentifier(superclassMethod, method);
            // now we need to stick the parameters into an array, boxing if nessesary
            String[] params = method.getParameters();
            ca.iconst(params.length);
            ca.anewarray("java/lang/Object");
            int loadPosition = 1;
            for (int i = 0; i < params.length; ++i) {
                ca.dup();
                ca.iconst(i);
                String type = params[i];
                if (type.length() == 1) { // primitive
                    char typeChar = type.charAt(0);
                    switch (typeChar) {
                        case 'I':
                            ca.iload(loadPosition);
                            Boxing.boxInt(ca);
                            break;
                        case 'S':
                            ca.iload(loadPosition);
                            Boxing.boxShort(ca);
                            break;
                        case 'B':
                            ca.iload(loadPosition);
                            Boxing.boxByte(ca);
                            break;
                        case 'Z':
                            ca.iload(loadPosition);
                            Boxing.boxBoolean(ca);
                            break;
                        case 'C':
                            ca.iload(loadPosition);
                            Boxing.boxChar(ca);
                            break;
                        case 'D':
                            ca.dload(loadPosition);
                            Boxing.boxDouble(ca);
                            loadPosition++;
                            break;
                        case 'J':
                            ca.lload(loadPosition);
                            Boxing.boxLong(ca);
                            loadPosition++;
                            break;
                        case 'F':
                            ca.fload(loadPosition);
                            Boxing.boxFloat(ca);
                            break;
                        default:
                            throw new RuntimeException("Unknown primitive type descriptor: " + typeChar);
                    }
                } else {
                    ca.aload(loadPosition);
                }
                ca.aastore();
                loadPosition++;
            }
            ca.invokeinterface(InvocationHandler.class.getName(), "invoke",
                    "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");

            if (superclassMethod.getReturnType() != void.class) {
                if (superclassMethod.getReturnType().isPrimitive()) {
                    Boxing.unbox(ca, method.getReturnType());
                } else {
                    ca.checkcast(superclassMethod.getReturnType().getName());
                }
            }
            ca.returnInstruction();
        }
View Full Code Here

Examples of org.jboss.classfilewriter.code.CodeAttribute

         * @param method the class method to populate
         * @param constructor the constructor to override
         */
        @Override
        public void overrideConstructor(ClassMethod method, Constructor<?> constructor) {
            CodeAttribute ca = method.getCodeAttribute();
            ca.aload(0);
            ca.iconst(0);
            ca.putfield(getClassName(), CONSTRUCTED_GUARD, "Z");
            ca.aload(0);
            ca.loadMethodParameters();
            ca.invokespecial(constructor);
            ca.aload(0);
            ca.iconst(1);
            ca.putfield(getClassName(), CONSTRUCTED_GUARD, "Z");
            ca.returnInstruction();
        }
View Full Code Here

Examples of org.jboss.classfilewriter.code.CodeAttribute

         * @param superclassMethod the method to override
         */
        @Override
        public void overrideMethod(ClassMethod method, Method superclassMethod) {
            // superClassMethod will be null
            CodeAttribute ca = method.getCodeAttribute();
            ca.newInstruction(serializableProxyClass.getName());
            ca.dup();
            ca.invokespecial(serializableProxyClass.getName(), "<init>", "()V");
            ca.dup();
            ca.aload(0);
            ca.invokeinterface(SerializableProxy.class.getName(), "setProxyInstance", "(Ljava/lang/Object;)V");
            ca.returnInstruction();
        }
View Full Code Here

Examples of org.jboss.forge.furnace.proxy.javassist.bytecode.CodeAttribute

    public CtClass[] mayThrow() {
        ClassPool pool = thisClass.getClassPool();
        ConstPool cp = thisMethod.getConstPool();
        LinkedList list = new LinkedList();
        try {
            CodeAttribute ca = thisMethod.getCodeAttribute();
            ExceptionTable et = ca.getExceptionTable();
            int pos = currentPos;
            int n = et.size();
            for (int i = 0; i < n; ++i)
                if (et.startPc(i) <= pos && pos < et.endPc(i)) {
                    int t = et.catchType(i);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.