Examples of Insn


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

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

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

        //@olsen: disabled code
        if (false) {
            // reset jdoFlags = LOAD_REQUIRED
            insn = insn.append(Insn.create(opc_aload_0));
            insn = insn.append(Insn.create(opc_iconst_1));
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             JDO_PC_jdoFlags_Name,
                                             JDO_PC_jdoFlags_Sig)));
        }

        // iterate over all declared fields of the class
        final ClassField[] managedFields = null; //analyzer.annotatedFields();
        final int managedFieldCount = managedFields.length;
        for (int i = 0; i < managedFieldCount; i++) {
            final ClassField field = managedFields[i];
            final String fieldName = field.name().asString();
            final String fieldSig = field.signature().asString();

/*
            // ignore primary managed fields
            if (field.isManaged())
                continue;
*/

/*
            //@olsen: disconnect mutable SCOs before clear
            if (field.isMutableSCO()) {
                // fetch field
                insn = insn.append(Insn.create(opc_aload_0));
                insn = insn.append(
                    Insn.create(opc_getfield,
                                pool.addFieldRef(
                                    className,
                                    fieldName,
                                    fieldSig)));

                // test whether instanceof SCO base type
                // skip disconnecting if == 0
                final ConstClass cc
                    = pool.addClass(JDO_SecondClassObjectBase_Path);
                InsnTarget disconnect = new InsnTarget();
                InsnTarget afterDisconnect = new InsnTarget();
                insn = insn.append(
                    Insn.create(opc_dup));
                insn = insn.append(
                    Insn.create(opc_instanceof,
                                cc));
                insn = insn.append(
                    Insn.create(opc_ifne,
                                disconnect));

                // pop field and skip disconnecting
                insn = insn.append(
                    Insn.create(opc_pop));
                insn = insn.append(
                    Insn.create(opc_goto, afterDisconnect));

                // disconnect SCO field's object
                insn = insn.append(disconnect);

                // cast to SCO base type
                insn = insn.append(
                    Insn.create(opc_checkcast,
                                cc));

                // call method: void unsetOwner();
                final int requiredStack = 1;
                insn = insn.append(
                    new InsnInterfaceInvoke(
                        pool.addInterfaceMethodRef(
                            JDO_SecondClassObjectBase_Path,
                            "unsetOwner",
                            "()V"),
                        requiredStack));

                insn = insn.append(afterDisconnect);
            }
*/

            // get this
            insn = insn.append(Insn.create(opc_aload_0));

            // use the getMethodReturn type to decide how to clear field
            switch (fieldSig.charAt(0)) {
            case 'D':
                insn = insn.append(Insn.create(opc_dconst_0));
                break;
            case 'F':
                insn = insn.append(Insn.create(opc_fconst_0));
                break;
            case 'J':
                insn = insn.append(Insn.create(opc_lconst_0));
                break;
            case 'Z':
            case 'C':
            case 'B':
            case 'S':
            case 'I':
                insn = insn.append(Insn.create(opc_iconst_0));
                break;
            case 'L':
            case '[':
                insn = insn.append(Insn.create(opc_aconst_null));
                break;
            default:
                throw new InternalError("Illegal field type: " + fieldSig);
            }

            // put default value to field
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             fieldName,
                                             fieldSig)));
        }

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

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

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

                pool.addUtf8(ExceptionsAttribute.expectedAttrName),
                pool.addClass("java/lang/CloneNotSupportedException"));

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

        // THISCLASS newObject = (THISCLASS) super.clone();
        final ConstClass superConstClass = classFile.superName();
        final ConstClass thisConstClass = classFile.className();
        affirm(thisConstClass != null);
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_invokespecial,
                        pool.addMethodRef(superConstClass.asString(),
                                          methodName,
                                          methodSig)));
        insn = insn.append(Insn.create(opc_checkcast, thisConstClass));

        // newObject.jdoStateManager = null;
        if (false)
        {
            insn = insn.append(Insn.create(opc_dup));
            insn = insn.append(Insn.create(opc_aconst_null));
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             JDO_PC_jdoStateManager_Name,
                                             JDO_PC_jdoStateManager_Sig)));
        }

        // newObject.jdoFlags = 0;
        if (false)
        {
            insn = insn.append(Insn.create(opc_dup));
            insn = insn.append(Insn.create(opc_iconst_0));
            insn = insn.append(
                Insn.create(opc_putfield,
                            pool.addFieldRef(className,
                                             JDO_PC_jdoFlags_Name,
                                             JDO_PC_jdoFlags_Sig)));
        }

        // return newObject;

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

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

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

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

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

        insn = appendThrowJavaException(
            insn, JAVA_UnsupportedOperationException_Path,
            "Method " + methodName + " not yet implemented");
View Full Code Here

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

    {
        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

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

        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

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

        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

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

        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

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

        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

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

        final int accessFlags = JDO_PC_jdoNewInstance_Object_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_3));

        // class on instance pc.jdoCopyKeyFieldsFromObjectId(oid)
        //^olsen: javac uses the truelly declaring class
        final String pcKeyOwnerClassName = analyzer.getPCKeyOwnerClassName();
        affirm(pcKeyOwnerClassName != null);
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(Insn.create(opc_aload_2));
        insn = insn.append(
            Insn.create(opc_invokevirtual,
                        pool.addMethodRef(
                            pcKeyOwnerClassName,
                            JDO_PC_jdoCopyKeyFieldsFromObjectId_Name,
                            JDO_PC_jdoCopyKeyFieldsFromObjectId_Sig)));

        // init jdo flags and assign argument to sm
        insn = insn.append(Insn.create(opc_aload_3));
        insn = insn.append(Insn.create(opc_iconst_1));
        insn = insn.append(
            Insn.create(opc_putfield,
                        getjdoFlagsFieldRef()));
        insn = insn.append(Insn.create(opc_aload_3));
        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_3));
        insn = insn.append(Insn.create(opc_areturn));

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

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

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

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

        // generate the begin code
        insn = appendBeginProvideReplaceField(insn);
       
        // generate the switch code
        final SizeHolder sizeHolder = new SizeHolder();
        insn = appendSwitchForProvideField(insn, sizeHolder);
       
        // generate the default-branch code with throw/return
        insn = appendEndProvideReplaceField(insn,
                                            JDO_PC_jdoProvideField_Name,
                                            JDO_PC_jdoProvideField_Sig);

        // end of method body
        affirm(insn.opcode() == opc_athrow || insn.opcode() == opc_return);
       
        affirm(0 <= sizeHolder.size && sizeHolder.size <= 2);
        //System.out.println("sizeHolder.size = " + sizeHolder.size);
        final int maxStack = (sizeHolder.size == 0
                              ? 3 : (sizeHolder.size == 1 ? 4 : 5));
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.