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

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


        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);

        // write argument to field and return
View Full Code Here


        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        // get field's sig and compute first non-parameter slot
        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
View Full Code Here

        affirm(methodSig != null);     
        final ExceptionsAttribute exceptAttr = null;

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

        // get field's sig and compute first non-parameter slot
        final ConstFieldRef fieldRef = getAnnotatedFieldRefs()[fieldIndex];
        affirm(fieldRef != null);
        final String sig = fieldRef.nameAndType().signature().asString();
        affirm(sig != null && sig.length() > 0);
        final int fieldSize = ((sig.equals("J") || sig.equals("D")) ? 2 : 1);
        final int varStart = fieldSize + 1;

        // directly write argument and retrurn if flags are != READ_WRITE_OK
        final InsnTarget mediate = new InsnTarget();
        insn = insn.append(Insn.create(opc_aload_0));
        insn = insn.append(
            Insn.create(opc_getfield,
                        getjdoFlagsFieldRef()));
        insn = insn.append(Insn.create(opc_ifne, mediate));
        insn = appendDirectWriteReturn(insn, fieldRef);

        // mediate access
        insn = insn.append(mediate);
        insn = appendMediatedWriteAccess(insn, fieldIndex, fieldRef, varStart);

        // end of method body

        final CodeAttribute codeAttr
View Full Code Here

        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

                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

        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

    {
        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

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.