Package org.apache.jdo.impl.enhancer.classfile

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


                pool.addUtf8(ExceptionsAttribute.expectedAttrName),
                pool.addClass("java/io/IOException"));
       
        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // call jdoPreSerialize
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            className,
                            JDO_PC_jdoPreSerialize_Name,
                            JDO_PC_jdoPreSerialize_Sig)));

        // call out.defaultWriteObject();
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            JAVA_ObjectOutputStream_Path,
                            JAVA_ObjectOutputStream_defaultWriteObject_Name,
                            JDO_PC_jdoPreSerialize_Sig)));
       
        // end of method body
        insn = insn.append(Insn.create(opc_return));

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                1, // maxStack
                                2, // maxLocals
View Full Code Here


    {
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;
       
        // invoke jdoPreSerialize
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            className,
                            JDO_PC_jdoPreSerialize_Name,
                            JDO_PC_jdoPreSerialize_Sig)));
View Full Code Here

    {
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // store the sm field into local var
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(
                opc_getfield,
                getjdoStateManagerFieldRef()));
        insn = insn.append(Insn.create(opc_astore_1));

        // test the sm field and do the call if nonnull
        InsnTarget noncall = new InsnTarget();
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_ifnull, noncall));

        // call the sm's method with 'this' argument and return
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            new InsnInterfaceInvoke(
                pool.addInterfaceMethodRef(
                    JDO_StateManager_Path,
                    delegateName,
                    delegateSig),
                countMethodArgWords(delegateSig)));
        insn = insn.append(Insn.create(opc_ireturn));

        // return false
        insn = insn.append(noncall);
        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
View Full Code Here

    {
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // store the sm field into local var
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(
                opc_getfield,
                getjdoStateManagerFieldRef()));
        insn = insn.append(Insn.create(opc_astore_1));

        // test the sm field and do the call if nonnull
        InsnTarget noncall = new InsnTarget();
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_ifnull, noncall));

        // call the sm's method with 'this' argument and return
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            new InsnInterfaceInvoke(
                pool.addInterfaceMethodRef(
                    JDO_StateManager_Path,
                    delegateName,
                    delegateSig),
                countMethodArgWords(delegateSig)));
        insn = insn.append(Insn.create(opc_areturn));

        // return null
        insn = insn.append(noncall);
        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
View Full Code Here

    {
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // check arg
        insn = appendCheckVarNonNull(insn, 1,
                                     JAVA_IllegalArgumentException_Path,
                                     "arg1");

        // store the array argument length into local var
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_arraylength));
        insn = insn.append(Insn.create(opc_istore_2));

        // init loop counter and goto loop check
        final InsnTarget loopcheck = new InsnTarget();
        insn = insn.append(Insn.create(opc_iconst_0));
        insn = insn.append(Insn.create(opc_istore_3));
        insn = insn.append(Insn.create(opc_goto, loopcheck));

        // loop body: call self-delegating method with array element
        final InsnTarget loopbody = new InsnTarget();
        insn = insn.append(loopbody);
        insn = insn.append(Insn.create(opc_aload_0));

        // select element from array argument at loop counter
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(Insn.create(opc_iload_3));
        insn = insn.append(Insn.create(opc_iaload));

        // call self-delegating method
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            className,
                            delegateName,
                            delegateSig)));

        // loop counter increment
        insn = insn.append(new InsnIInc(3, 1));

        // loop termination check
        insn = insn.append(loopcheck);
        insn = insn.append(Insn.create(opc_iload_3));
        insn = insn.append(Insn.create(opc_iload_2));
        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
View Full Code Here

        final int accessFlags = SUNJDO_PC_sunjdoClassForName_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // invoke the Class.forName(String) method with argument
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_invokestatic,
                        pool.addMethodRef(
                            JAVA_Class_Path,
                            JAVA_Class_forName_Name,
                            JAVA_Class_forName_Sig)));

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

        // begin of exception handler
        final InsnTarget end = new InsnTarget();
        final InsnTarget beginHandler = end;
        insn = insn.append(beginHandler);

        // create NoClassDefFoundError with message from caught exception
        insn = insn.append(Insn.create(opc_astore_1));
        insn = insn.append(
            Insn.create(opc_new,
                        pool.addClass(JAVA_NoClassDefFoundError_Path)));
        insn = insn.append(Insn.create(opc_dup));
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(
            Insn.create(
                opc_invokevirtual,
                pool.addMethodRef(
                    JAVA_Throwable_Path,
                    JAVA_Throwable_getMessage_Name,
                    JAVA_Throwable_getMessage_Sig)));
        insn = insn.append(
            Insn.create(
                opc_invokespecial,
                pool.addMethodRef(
                    JAVA_NoClassDefFoundError_Path,
                    JAVA_NoClassDefFoundError_NoClassDefFoundError_Name,
                    JAVA_NoClassDefFoundError_NoClassDefFoundError_Sig)));

        // end of exception handler
        insn = insn.append(Insn.create(opc_athrow));

        // create exception table
        final ConstClass catchType
            = pool.addClass(JAVA_ClassNotFoundException_Path);
        final ExceptionRange exceptionRange
View Full Code Here

        final int managedFieldCount = analyzer.getManagedFieldCount();
        affirm(managedFieldCount >= 0);

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // push total (absolute) number of managed fields
        final boolean isPCRoot = analyzer.isAugmentableAsRoot();
        if (isPCRoot) {
            insn = insn.append(InsnUtils.integerConstant(managedFieldCount, pool));
        }
        else {
            final ConstClass superConstClass = classFile.superName();
            affirm(superConstClass != null);
            final String superClassName = superConstClass.asString();
            affirm(superClassName != null);
            // call the superclass' jdoGetManagedFieldCount method
            insn = insn.append(
                Insn.create(opc_invokestatic,
                            pool.addMethodRef(
                                superClassName,
                                JDO_PC_jdoGetManagedFieldCount_Name,
                                JDO_PC_jdoGetManagedFieldCount_Sig)));
            insn = insn.append(InsnUtils.integerConstant(managedFieldCount, pool));
            insn = insn.append(Insn.create(opc_iadd));
        }

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

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                isPCRoot ? 1 : 2, // maxStack
                                0, // maxLocals
View Full Code Here

        final int accessFlags = JAVA_clinit_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // initialize jdo fields
        insn = initJdoInheritedFieldCount(insn);
        insn = initJdoFieldNames(insn);
        insn = initJdoFieldTypes(insn);
        insn = initJdoFieldFlags(insn);
        insn = initJdoPersistenceCapableSuperclass(insn);

        // invoke registerClass
        insn = registerClass(insn);

        // add or extend the static initializer
        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                7, // maxStack
                                0, // maxLocals
                                begin,
                                new ExceptionTable(),
                                new AttributeVector());

        if (analyzer.hasStaticInitializer()) {
            // not end of method body
            augmenter.prependMethod(methodName, methodSig,
                                    codeAttr, exceptAttr);
        } else {
            // end of method body
            insn = insn.append(Insn.create(opc_return));
            augmenter.addMethod(methodName, methodSig, accessFlags,
                                codeAttr, exceptAttr);
        }
    }
View Full Code Here

        final int accessFlags = JDO_PC_jdoNewInstance_Mods;
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

        // push a newly created an instance of this class
        final ConstClass thisConstClass = classFile.className();
        affirm(thisConstClass != null);
        insn = insn.append(Insn.create(opc_new, thisConstClass));
        insn = insn.append(Insn.create(opc_dup));
        insn = insn.append(
            Insn.create(opc_invokespecial,
                        pool.addMethodRef(
                            className,
                            NameHelper.constructorName(),
                            NameHelper.constructorSig())));
        insn = insn.append(Insn.create(opc_astore_2));

        // init jdo flags and assign argument to sm
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(Insn.create(opc_iconst_1));
        insn = insn.append(
            Insn.create(opc_putfield,
                        getjdoFlagsFieldRef()));
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(Insn.create(opc_aload_1));
        insn = insn.append(
            Insn.create(opc_putfield,
                        getjdoStateManagerFieldRef()));

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

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                2, // maxStack
                                3, // maxLocals
View Full Code Here

        affirm((accessFlags & ACCStatic) == 0);
        final ExceptionsAttribute exceptAttr = null;

        // begin of method body
        final InsnTarget begin = new InsnTarget();
        Insn insn = begin;

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

        final CodeAttribute codeAttr
            = new CodeAttribute(getCodeAttributeUtf8(),
                                0, // maxStack
                                countMethodArgWords(methodSig), // maxLocals
View Full Code Here

TOP

Related Classes of org.apache.jdo.impl.enhancer.classfile.Insn

Copyright © 2018 www.massapicom. 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.